Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: XML::XPath tricks and tips

by gmpassos (Priest)
on Sep 02, 2004 at 16:03 UTC ( [id://387959]=note: print w/replies, xml ) Need Help??


in reply to XML::XPath tricks and tips

If you want to just access XML values you don't need to use XPath to find this informations. You can use it, but the XPath implementation in Perl (XML::XPath), in my opinion, is not very intuitive to use.

What you can do is to use some module that loads XML into a HASH tree, and access the values directly from the tree. You can take a look at XML::Simple (more popular) and XML::Smart (well, I'm the author of it, so I shouldn't say what is better).

Well, the main idea of XML::Smart is to enable the use of XML by programmers without need to really know the XML format. Here's a simple example of how to do what you want:

use XML::Smart ; my $xml = new XML::Smart('available_batchnyyn.xml'); my @avaliables = @{ $xml->{AvailableBatch}{Available} } ; foreach my $avaliables_i ( @avaliables ) { my $part = $avaliables_i->{Part} ; my $qty = $avaliables_i->{Qty} ; print "Part: $part ; Qty: $qty\n" ; }

Graciliano M. P.
"Creativity is the expression of the liberty".

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-20 10:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found