lib::libXML parsing comments

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I have to parse an XML document and rewrite it, after sorting some of
the nodes. Some of these nodes have assocated comments which I have been
told have to remain beside their node.

However walking the list of nodes returned by XML::LibXML's
getChildNodes or childNodes I never see XML_COMMENT_NODE returned. It
looks as though the parser is discarding comments.

perl : v5.8.8
XML::LibXML : 1.7

Comments please:-)

Re: lib::libXML parsing comments

Quoth (Fergus McMenemie):
Quoted text here. Click to load it

Works for me:


    use 5.010;
    use warnings;
    use strict;
    use XML::LibXML;

    my $X = XML::LibXML->load_xml(IO => \*DATA);
    say sprintf "[%s] [%s]", $_->nodeName, $_->textContent
        for $X->documentElement->childNodes;

    <?xml version="1.0"?>

        <!-- comment -->

    [#text] [
    [#comment] [ comment ]
    [#text] [
    [element] []
    [#text] [

Can you post a miminal example which doesn't do what you want?


Re: lib::libXML parsing comments

Hummm, I had cancelled this message but I guess either cancelling did
not work or I was not quick enough. However everything works fine. I
had not properly accounted for how the comment was nested within my
documents structure.

Sorry for wasting your time. But on the other hand your example is

Quoted text here. Click to load it

Re: lib::libXML parsing comments

   at 03:50 AM, (Fergus McMenemie) said:

Quoted text here. Click to load it

Due to rogue cancels, the big players mo l;onger honor cancels from
the general public.

Shmuel (Seymour J.) Metz, SysProg and JOAT  <

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to

Site Timeline