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

In reply to Re: XML::Simple usage question (steriods) by Anonymous Monk
in thread XML::Simple usage question by gri6507

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.