Re: libXML, append and order

Daniel Perrett <[email protected]> Tue, 9 Aug 2011 11:04:08 +0100
Newsgroups gmane.comp.lang.perl.xml
Message-ID <OFF30ED279.D23D80E0-ON802578E7.00359D70-802578E7.00374F75@cambridge.org>
This is how I tend to do it:

my $newNode = XML::LibXML::Element->new('new-element');
if ($parent->findnodes('node()'))
{
        $refNode = ${[$parent->findnodes('node()')]}[0]; # get first child 
node
        $parent->insertBefore($newNode, $refNode);
}
else
{
        $parent->appendChild($newNode);
}

Is this what you mean?

There might be a case for writing LibXML methods for common tasks like 
this. Or, there might be an easier way of doing all this.

Daniel



From:   Maurice Mengel <[email protected]>
To:     [email protected]
Date:   09/08/2011 10:44
Subject:        libXML, append and order
Sent by:        [email protected]



Hi friends,

I have a question regarding how to add nodes with LibXML in order.

i am trying to add a node to a document using LibXML, currently with
appendChild. It works (node gets added), but the result is in the
wrong order. As documented node gets appended at the end of the
nodelist.

Is there away to add something to the beginning of a lodelist?

Thanks!

maurice
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs