Re: XML::LibXML - Mixing XPath with a document fragment

Emmanuel Rodriguez <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
On Thu, Jan 29, 2009 at 11:12 AM, Petr Pajas <[email protected]> wrote:
> On čt 29. ledna 2009, Petr Pajas wrote:
>> On čt 29. ledna 2009, Emmanuel Rodriguez wrote:
>> > Hi,
>> >
>> > I have an XML document that was generated with document
>> > fragments by an external function. This gave me some struggle
>> > because I was trying to use an XPath expression to access some
>> > nodes and couldn't reach them. This is due to the fact that
>> > even though the document fragment seems transparent it's still
>> > in the document and brakes the parent/child/sibling relation
>> > ship. This makes it a difficult to use XPath to search for
>> > nodes.
>> >
>> > Is there a way to clean document of all document fragments
>> > besides $xml =
>> > XML::LibXML->new()->parse_string($xml->toString()); ? Should
>> > document fragments be avoided?
>> >
>> > For the curious, I have attached a test case that shows the
>> > problems I had parsing the document.
>>
>> Hallo Emmanuel!
>>
>> A fragment node should never have appeared as a child of another
>> node; that's the bug!
>
> oh, and the bug is documented:-)
>
> addChild:
>
> As an alternative to appendChild() one can use the addChild()
> function. This function is a bit faster, because it avoids all DOM
> conformity checks.
>
> Well, in that case I might just add a simple node-type test and
> croak on fragments (and possibly other invalid node types). That
> will not cause any significant slow down.
>
> One should use appendChild() for correct DOM behavior.
>
Thanks Petr.
-- 
Emmanuel Rodriguez
_______________________________________________
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.