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

Discussion in 'Perl Misc' started by Peter Makholm, Mar 12, 2010.

  1. 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></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, Mar 12, 2010
    #1
    1. Advertising

  2. Peter Makholm <> writes:

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

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

    //Makholm
     
    Peter Makholm, Mar 12, 2010
    #2
    1. Advertising

  3. Peter Makholm

    Permostat Guest

    On Mar 12, 4:38 am, Peter Makholm <> wrote:
    > Peter Makholm <> writes:
    > >     my $node = XML::LibXML->new()->parse_balanced_chunk(
    > >         '<owner></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></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-
     
    Permostat, Mar 12, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Williams
    Replies:
    1
    Views:
    1,457
    Dylan Parry
    Jun 3, 2005
  2. Ian Gregory
    Replies:
    1
    Views:
    530
  3. Tony Prichard
    Replies:
    0
    Views:
    788
    Tony Prichard
    Dec 12, 2003
  4. Olav
    Replies:
    3
    Views:
    4,368
  5. Martin Molema
    Replies:
    2
    Views:
    158
    dhtml
    Jan 11, 2009
Loading...

Share This Page