Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: XML::Simple usage question (steriods)

by Anonymous Monk
on Jul 13, 2012 at 23:03 UTC ( [id://981737]=note: print w/replies, xml ) Need Help??


in reply to XML::Simple usage question

XML::Rules, its XML::Simple on steriods, if you need array-o-hash type structures

#!/usr/bin/perl -- use strict; use warnings; use XML::Rules; use Data::Dump qw/ dd /; my $ta = XML::Rules->new( qw/ stripspaces 8 /, rules => [ _default => 'raw', ], ); my $da = XML::Rules->new( qw/ stripspaces 8 /, rules => [ a => 'content', _default => 'raw', ], ); dd $ta->parse( q(<a><b type="1"/><b type="2"/><c/><b type="3"/></a>) +); dd $da->parse( q(<a><b type="1"/><b type="2"/><c/><b type="3"/></a>) +); dd $da->parse( q(<a><b type="1"/><b type="2"/><c/><b type="3">tada</b +></a>) ); __END__ [ "a", { _content => [ ["b", { type => 1 }], ["b", { type => 2 }], ["c", {}], ["b", { type => 3 }], ], }, ] { a => [ ["b", { type => 1 }], ["b", { type => 2 }], ["c", {}], ["b", { type => 3 }], ], } { a => [ ["b", { type => 1 }], ["b", { type => 2 }], ["c", {}], ["b", { _content => "tada", type => 3 }], ], }

And xsh is a step further

$ xsh -q $scratch/> open pm981718.xml /> ls / <?xml version="1.0"?> <a> <b type="1"/> <b type="2"/> <c/> <b type="3">tada</b> </a> /> for /a/* { pwd } /a/b[1] /a/b[2] /a/c /a/b[3] /> for /a/* { pwd; print @type; } /a/b[1] 1 /a/b[2] 2 /a/c /a/b[3] 3 /> for /a/* { pwd; for(@*){ echo xsh:path(.) " = " xsh:current(); }; } +; /a/b[1] /a/b[1]/@type = 1 /a/b[2] /a/b[2]/@type = 2 /a/c /a/b[3] /a/b[3]/@type = 3 /> /> quit saving .../.xsh2_history done

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2024-04-25 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found