Is there a reason to use the XML::LibXML::Number-object in my XML::LibXML-example?

Posted by sid_com on Stack Overflow See other posts from Stack Overflow or by sid_com
Published on 2010-05-18T10:03:14Z Indexed on 2010/05/18 21:30 UTC
Read the original article Hit count: 285

Filed under:
|

In this example I get to times '96'. Is there a possible case where I would need a XML::LibXML-Number-object to to achieve the goal?

#!/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="hours">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;

my $result = $root->find( '//files/age[@units="hours"]' );
$result = $result->get_node( 1 );
say ref $result; # XML::LibXML::Element
say $result->textContent; # 96

$result =  $root->find ( 'number( //files/age[@units="hours"] )' );
say ref $result; # XML::LibXML::Number
say $result; # 96

© Stack Overflow or respective owner

Related posts about perl

Related posts about xml-libxml