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
|
|---|