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

Re^2: XML: Simple - nested XML data

by PipTigger (Friar)
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!

-Pip@CPAN.Org
PipForPresident.Org


Comment on Re^2: XML: Simple - nested XML data
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-07-26 07:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls