XML::LibXML: Including xml fragments in a larger document

P

Peter Makholm

For a project I receive some XML fragments from a data base and have
to include it in a larger XML document created with XML::LibXML. With
version 1.66 of XML::LibXML I was able to to something like

my $doc = XML::LibXML::Document->new('1.0', 'utf-8' );
my $root = $doc->createElement("X:root");
$doc->setDocumentElement($root);

my $node = XML::LibXML->new()->parse_balanced_chunk(
'<owner>[email protected]</owner>'
);
$doc->adoptNode($node);
$root->addChild($node);

But with version 1.70 of XML::LibXML this fails with an error saying
'Adding document fragments with addChild not supported!'

Is there a working way to implement this?

//Makholm
 
P

Peter Makholm

Peter Makholm said:
my $node = XML::LibXML->new()->parse_balanced_chunk(
'<owner>[email protected]</owner>'
);
$doc->adoptNode($node);
$root->addChild($node);

After a bit more trying I can up with this solution:

my $fragment = XML::LibXML->new()->parse_balanced_chunk(
'<owner>[email protected]</owner>'
);
for my $node ($fragment->childNodes) {
$root->addChild($node);
}

It works in both XML::LibXML version 1.66 and 1.70.

//Makholm
 
P

Permostat

After a bit more trying I can up with this solution:

    my $fragment = XML::LibXML->new()->parse_balanced_chunk(
        '<owner>[email protected]</owner>'
    );
    for my $node ($fragment->childNodes) {
        $root->addChild($node);
    }

It works in both XML::LibXML version 1.66 and 1.70.

//Makholm

Well aren't you just a hunky dory Fucker.

sperm-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top