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

Re: xml::twig gathering all element and att and its value question

by Jenda (Abbot)
on Nov 12, 2008 at 15:15 UTC ( #723180=note: print w/replies, xml ) Need Help??


in reply to xml::twig gathering all element and att and its value question

use XML::Rules; XML::Rules->new( stripspaces => 7, rules => { lease => sub {return 'lease' => $_[1]->{true}}, extra_device => sub {return 'extra_device' => $_[1]->{value}}, computer => sub { if ($_[1]->{extra_device}) { print "computer id: $_[1]->{id} type: $_[1]->{type} os +: $_[1]->{os} lease:$_[1]->{lease} extra_device=$_[1]->{extra_device} +\n"; } else { print "computer id: $_[1]->{id} type: $_[1]->{type} os +: $_[1]->{os} lease:$_[1]->{lease}\n"; } return; } } )->parse(\*DATA); __DATA__ <config> <computer id="one" type="mac" os="XP" > <lease true="yes" /> <extra_device value="scanner"/> </computer> <computer id="two" type="pc" os="NT" > <lease true="no" /> </computer> </config>

Sometimes it's better to reach for a different hammer. Even if you already have a hammer in your hand.

  • Comment on Re: xml::twig gathering all element and att and its value question
  • Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2022-05-23 15:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?