Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: finding each and every node of a xml document

by tobyink (Canon)
on Apr 23, 2012 at 09:36 UTC ( [id://966560]=note: print w/replies, xml ) Need Help??


in reply to finding each and every node of a xml document

This example should do the trick. Note that DTD nodes don't appear in the XPath model, so I grep for those first.

use 5.010; use XML::LibXML 1.70 ':all'; my $dom = XML::LibXML-> load_xml(IO => \*DATA); my @nodes = ( (grep { $_->nodeType == XML_DTD_NODE } $dom->childNodes), $dom->findnodes('//node() | //@*'), ); foreach (@nodes) { say "Node name: ", $_->nodeName; say "Node path: ", $_->nodePath; say "---"; } __DATA__ <!DOCTYPE foo> <foo> <?processing-instruction?> <!-- a comment --> <bar attr="1" /> </foo>
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-25 13:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found