Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

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

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


Hi,

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found