in reply to xpath query

You're doing it wrong.
use XML::LibXML qw(); XML::LibXML ->load_xml(string => <<'XML')->find('//dependency[not(version)]'); <project> <dependency> <!-- find all such dependency tags --> <groupId>com.solarmetric</groupId> <artifactId>kodo-jdo-runtime</artifactId> </dependency> <dependency> <groupId>javax.jdo</groupId> <artifactId>jdo</artifactId> <version>1.0.2</version> </dependency> </project> XML
The expression returns a XML::LibXML::NodeList referencing a single XML::LibXML::Element representing the first dependency element.find(

Replies are listed 'Best First'.
Re^2: xpath query
by ikegami (Patriarch) on Dec 27, 2011 at 11:13 UTC
    His XPath searched for "dependency" elements regardless of their namespace. Your XPath searches for "dependency" elements in the null namespace.
Re^2: xpath query
by mojo-jojo (Novice) on Dec 28, 2011 at 06:03 UTC
    why cant I find with the xpath query I have and the code I am using, cant I change the query to make it work?
      Found the solution by using the following code
      my $xp = XML::XPath->new( filename => $_[0] ); my $nodeset = $xp->find('//dependency[not(child::version)] '); +# find all authors foreach my $node ( $nodeset->get_nodelist ) { print XML::XPath::XMLParser::as_string($node)."\n\n"; }