Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

textContent() method in XML::LibXML ...

by biswanath_c (Beadle)
on Oct 15, 2009 at 20:48 UTC ( #801427=perlquestion: print w/replies, xml ) Need Help??

biswanath_c has asked for the wisdom of the Perl Monks concerning the following question:


I was trying to parse an XML doc using XML::LibXML package... I was trying to use textContent() method on a node element to get a node's value. But it gave me the node's value ALONG WITH THE child's value and the grandchild's value!!

What method should i use if i want only the current node's value and NOT the children's value?!

  • Comment on textContent() method in XML::LibXML ...

Replies are listed 'Best First'.
Re: textContent() method in XML::LibXML ...
by ramrod (Curate) on Oct 15, 2009 at 21:01 UTC
    According to the libXML documentation this is what I would expect.

    Try nodeValue.
    Or maybe use a different Xpath along with the XML::LibXML::Text module.

    As with some of your more recent posts, we could help you out more with a sample of the xml, and the xpath you are trying.

      nodeValue() worked! Thanks a lot!! That was VERY helpful! nodeValue() just picks the value of the current node. textCOntent() collates the values of the node and all its children and it's children's children and so on until the leaf is reached!!!

      Thanks again!

        I am trying with nodeValue() it not working

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://801427]
Approved by moritz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2020-10-22 04:53 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (225 votes). Check out past polls.