Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: XML: Simple - nested XML data

by PipTigger (Hermit)
on Dec 28, 2007 at 05:18 UTC ( #659301=note: print w/replies, xml ) Need Help??

in reply to Re: XML: Simple - nested XML data
in thread XML: Simple - nested XML data

I think that should've been XML::XPath ... which I inherited from for my XML::Tidy module. You might try:

#!/usr/bin/perl use strict; use warnings; use XML::XPath; my $xpob = XML::XPath->new('xml' => '<SuperItem> <UserID>1234</UserID> <MajorItems> <MinorItem> <Item>Box</Item> </MinorItem> </MajorItems> <MajorItems> <MinorItem> <Item>Suitcase</Item> </MinorItem> </MajorItems> </SuperItem>'); my @itmz = $xpob->findnodes('//Item'); # retn nodez in doc ordr print $itmz[1]->getChildNode(1)->getValue(); # XPath indices are 1-bas +ed # ... so the abov line takes the 2nd <Item /> elem (Bcuz Perl is 0-bas +ed) # && traverses down to its 1st child-node (this time no more nested el +emz # but just a TextNode as the only child) to print that value: "Suitcas +e"

XPath is good shit. Just today, I used it in a COLLADA file with: '//node[@type="JOINT"]' to give me all the elements that describe animation bones for a Wii game I'm working on. Tim sure is Toady. ;) Have fun!


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2021-09-20 09:20 GMT
Find Nodes?
    Voting Booth?

    No recent polls found