Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: XML::LibXML::XPathContext findnodes() Question

by AbrahamB (Initiate)
on Dec 19, 2008 at 20:54 UTC ( [id://731657]=note: print w/replies, xml ) Need Help??


in reply to Re: XML::LibXML::XPathContext findnodes() Question
in thread XML::LibXML::XPathContext findnodes() Question

I'm trying to test the existence of two separate elements.
Like /root && /root/element1. I want true if both exist, false if one exists.

The xpath can certainly be much better, but this is a simplified example from an xml-grep program I am working on.
I'm trying to add the functionality to test for the existence of 2 nodes separated by ' and '. I may need to use find() or findvalue() for these types of xpaths.

Thanks for your time!
  • Comment on Re^2: XML::LibXML::XPathContext findnodes() Question

Replies are listed 'Best First'.
Re^3: XML::LibXML::XPathContext findnodes() Question
by runrig (Abbot) on Dec 19, 2008 at 23:31 UTC
    If /root/element1 exists, then /root certainly exists.
Re^3: XML::LibXML::XPathContext findnodes() Question
by roman (Monk) on Dec 20, 2008 at 10:00 UTC

    You should probably use $doc->findvalue instead of findnodes because your XPath expression doesn't return a nodeset but boolean value.

    warn $doc->findvalue('/root and /root/element1'), "\n"; warn $doc->findvalue('/root and /root/nosuch'), "\n";

    yields:

    true false

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-24 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found