I'm trying to parse an XML like the one below with XML::Simple. I'm not sure what loop I should be using, I thought about using a for loop but it will only parse all the <level> but not the <study> (<study> is the lowest level but can appear at any level in the XML as you can see)
for my $level1_ref (@{$report_config->{"levels"}->{"level"}}) {
print...
}
Here's the XML
<config>
<levels name="a" target="29.6">
<level name="b" weight="50" target="35.1">
<study id="32" name="i" weight="30" />
<study id="36" name="j" weight="70" />
</level>
<study id="37" name="k" weight="15" />
<level name="c" weight="13" target="22.1">
<level name="d" weight="69.2">
<level name="e" weight="44.4">
<study id="34" name="l" weight="50" />
<study id="27" name="m" weight="50" />
</level>
<level name="f" weight="55.6">
<study id="25" name="n" weight="60" />
<study id="38" name="o" weight="40" />
</level>
</level>
<level name="g" weight="30.8">
<study id="50" name="p" weight="75" />
<study id="70" name="q" weight="25" />
</level>
</level>
<level name="h" weight="22" target="19.0">
<study id="40" name="r" weight="90.9" />
<study id="22" name="s" weight="9.1" />
</level>
</levels>
<study id="19" name="t" weight="0" spec="p0f7=2" />
<study id="19" name="u" weight="0" spec="p0f7=1" />
<study id="62" name="v" weight="0" />
</config>
cheers
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.