views:

49

answers:

1

From http://search.cpan.org/~pajas/XML-LibXML-1.70/lib/XML/LibXML/Node.pod:

find evaluates the XPath 1.0 expression using the current node as the context of the expression, and returns the result depending on what type of result the XPath expression had. For example, the XPath "1 * 3 + 52" results in a XML::LibXML::Number object being returned. Other expressions might return a XML::LibXML::Boolean object, or a XML::LibXML::Literal object (a string).

I suppose in my example the find returns a XML::LibXML::Literal object (a string). Could someone show me examples where find returns a XML::LibXML::Number object resp. a XML::LibXML::Boolean object?

#!/usr/bin/env perl
use warnings; use strict;
use 5.012;
use XML::LibXML;

my $xml_string =<<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<filesystem>
   <path>
     <dirname>/var</dirname>
     <files>
       <action>delete</action>
       <age units="days">10</age>
     </files>
     <files>
       <action>delete</action>
       <age units="hours">96</age>
     </files>
   </path>
</filesystem>
EOF
#/

my $doc = XML::LibXML->load_xml( string => $xml_string );
my $root = $doc->documentElement;

say $root->find( '//files[1]/action' );

outputs

delete

+1  A: 
$root -> find ("number(//files/age[@units = 'hours']"))
newtover