Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Question on XML::LibXML...

by biswanath_c (Beadle)
on Oct 14, 2009 at 19:33 UTC ( #801184=perlquestion: print w/replies, xml ) Need Help??
biswanath_c has asked for the wisdom of the Perl Monks concerning the following question:


I am trying to use XML::LibXML for parsing an XML doc. I was not able to find a proper API documentation for XML::LibXML. Could any of you point me to a decent API doc please?

I was able to get the root node of an xml doc and find a node with a particular name. But I was unable to get the value of the node. What is the API to get the value (a string) of an XML node using XML::LibXML?

Replies are listed 'Best First'.
Re: Question on XML::LibXML...
by SilasTheMonk (Chaplain) on Oct 14, 2009 at 19:44 UTC
    I usually find the CPAN documentation adequate though you do have to read several modules: XML::LibXML::Element, XML::LibXML::Node etc. A separate issue is that your documentation problem may be with XPath and not XML::LibXML. I find quite helpful in this regard. The real gotcha however is very often that when you try to parse a wild piece of XML, it often has a namespace set. The following example I have just grabbed out of some code of mine.
    my $parser = XML::LibXML->new(); my $doc = $parser->parse_string($xml_sitemap); print $doc->getDocumentElement->getNamespaces->getValue, "\n"; my $xpc = XML::LibXML::XPathContext->new(); $xpc->registerNs('x', $doc->getDocumentElement->getNamespaces->getValu +e); foreach my $u ($xpc->findnodes('//x:loc/child::text()',$doc)) { my $url = $u->toString; ....... }
Re: Question on XML::LibXML...
by ramrod (Curate) on Oct 14, 2009 at 19:58 UTC
    Sounds like you're looking for the text node. Use /text() in your xpath to reference this node.

    For example, if you want to point to a particular node:
    Or more generically:
    If you provide some sample xml, we could help out much more.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://801184]
Approved by SilasTheMonk
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2017-02-28 03:36 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (395 votes). Check out past polls.