| 1 |
# This is a test for: |
| 2 |
# https://rt.cpan.org/Public/Bug/Display.html?id=69520 |
| 3 |
|
| 4 |
=head1 DESCRIPTION |
| 5 |
|
| 6 |
IDs of elements is lost when importing nodes from another document. |
| 7 |
When call method 'importNode' executed function 'xmlNodeCopy' from the |
| 8 |
library libxml2, which does not import IDs. |
| 9 |
Propose to replace the call "xmlNodeCopy" on "xmlDocNodeCopy" in the file |
| 10 |
"dom.c". |
| 11 |
|
| 12 |
=head1 THANKS. |
| 13 |
|
| 14 |
Yuriy Ustushenko . |
| 15 |
|
| 16 |
=cut |
| 17 |
|
| 18 |
use strict; |
| 19 |
use warnings; |
| 20 |
|
| 21 |
use Test::More tests => 4; |
| 22 |
|
| 23 |
use XML::LibXML; |
| 24 |
|
| 25 |
{ |
| 26 |
my $doc = XML::LibXML->load_xml(string => <<'EOT'); |
| 27 |
<root> |
| 28 |
<item xml:id="id1">item1</item> |
| 29 |
</root> |
| 30 |
EOT |
| 31 |
|
| 32 |
my $elem = $doc->getElementById('id1'); |
| 33 |
# TEST |
| 34 |
ok ($elem, 'Orig doc has id1'); |
| 35 |
|
| 36 |
# TEST |
| 37 |
is ($elem->textContent(), 'item1', 'Content of orig doc elem id1'); |
| 38 |
|
| 39 |
my $doc2 = XML::LibXML->createDocument( "1.0", "UTF-8" ); |
| 40 |
$doc2->setDocumentElement( $doc2->importNode( $doc->documentElement() ) ); |
| 41 |
|
| 42 |
my $elem2 = $doc2->getElementById('id1'); |
| 43 |
# TEST |
| 44 |
ok ($elem2, 'Doc2 after importNode has id1'); |
| 45 |
|
| 46 |
# TEST |
| 47 |
is ($elem2->textContent(), 'item1', 'Doc2 after importNode has id1'); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
=head1 COPYRIGHT & LICENSE |
| 52 |
|
| 53 |
Copyright 2011 by Shlomi Fish |
| 54 |
|
| 55 |
This program is distributed under the MIT (X11) License: |
| 56 |
L<http://www.opensource.org/licenses/mit-license.php> |
| 57 |
|
| 58 |
Permission is hereby granted, free of charge, to any person |
| 59 |
obtaining a copy of this software and associated documentation |
| 60 |
files (the "Software"), to deal in the Software without |
| 61 |
restriction, including without limitation the rights to use, |
| 62 |
copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 63 |
copies of the Software, and to permit persons to whom the |
| 64 |
Software is furnished to do so, subject to the following |
| 65 |
conditions: |
| 66 |
|
| 67 |
The above copyright notice and this permission notice shall be |
| 68 |
included in all copies or substantial portions of the Software. |
| 69 |
|
| 70 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 71 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 72 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 73 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 74 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 75 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 76 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 77 |
OTHER DEALINGS IN THE SOFTWARE. |
| 78 |
|
| 79 |
=cut |