Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

24 views
Skip to first unread message

Peter Makholm

unread,
Mar 12, 2010, 5:07:40 AM3/12/10
to
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>pe...@makholm.net</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

Peter Makholm

unread,
Mar 12, 2010, 5:38:26 AM3/12/10
to
Peter Makholm <pe...@makholm.net> writes:

> my $node = XML::LibXML->new()->parse_balanced_chunk(
> '<owner>pe...@makholm.net</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>pe...@makholm.net</owner>'
);
for my $node ($fragment->childNodes) {
$root->addChild($node);
}

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

//Makholm

Permostat

unread,
Mar 12, 2010, 8:41:14 AM3/12/10
to

Well aren't you just a hunky dory Fucker.

sperm-

0 new messages