Re: join two xml docs with LibXML

Michael Ludwig <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Am 05.05.2010 um 17:48 schrieb Maurice Mengel:
> I am trying to join two xml documents (which are structured according to the same schema) with XML::Libxml. I would appreciate it very much if you can give me a clue. It should work with importNode, but I don't know how.  Thanks!

Joining two tree structures, hmm, that's a little vague.

If you're uncertain how to use the method, just take a look at *importNode* and *adoptNode* in XML::LibXML::Document, and maybe also at this example:


$ cat import-node.pl 
use common::sense;
use XML::LibXML;

my $parser = XML::LibXML->new;
my $doc  = $parser->parse_string( '<Urmel><a/><b/><c/></Urmel>' );
my $doc2 = $parser->parse_string( '<Urmel><D/><E/><F/></Urmel>' );

my @nodes = $doc->getElementsByTagName( 'b' );
for ( @nodes ) {
    my $imported = $doc2->importNode( $_ );
    $doc2->documentElement->appendChild( $imported );
}
print $doc2->toString;


$ perl import-node.pl 
<?xml version="1.0"?>
<Urmel><D/><E/><F/><b/></Urmel>


You can see that <b> has been imported.

-- 
Michael.Ludwig (#) XING.com

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.