I have an xml file whose structure basically contains one known tag, the root, and several tags within this that are not known.
<tables> <junk1 type="junk1" name="rates" requiredfields="date,rate"/> <junk2 type="junk2" name="demands" requiredfields=""/> <detail name="schema.detail" requiredfields="date,rate,scenarioname" +> <date mnemonic="date" name="The_Date" type="date" size="8"/> <rate mnemonic="rate" name="RATE" type="number" size=""/> </detail> <xyz name="schema.xyz" requiredfields="obsdate,wac,wala,wam"> <obsdate mnemonic="obsdate" name="asofdate" type="summed" calc="to +_char(asofdate,'mm/dd/yyyy')" size="8" required="false" cohort="true" +/> <model mnemonic="model" name="model" type="summed" size="" require +d="true" cohort="true" calc="trim('model')"/> <new mnemonic="new" name="ISNEW" type="char" size="" required="fal +se" cohort="true"/> <loancount mnemonic="loancount" name="LoanCount" type="summed" siz +e="8" required="false" cohort="fale" calc="sum(LOANCOUNT)"/> <cpr mnemonic="cpr" name="CPR" type="summed" size="8" calc="CASE WHEN SUM(a) != 0 THEN round((1-power(1-sum(b/ +100*a)/sum(a),12))*100,2) ELSE SUM(0) END" required="true" cohort="fa +lse"/> </xyz> </tables

I need to produce an output file from this that looks like:
table name   field name   type   size   required   calc

I am trying to use XML::Simple to do this. However all of the examples I have found use a XML file that has a more defined form so that you can reference specific nodes. The issue I have is that new tables are being added to, so I need be be able to loop over these items generically.

I tried the following:
my $xml = XMLin($xfile,ForceArray=>1)||die("unable to perform 'in' n") +; foreach $table (keys %{$xml->{tables}}){ print "$table\n"; }
thinking this would give me junk1, junk2, detail, and xyz but it actually doesn't return anything. It runs, but nothing is output. I thought that if I could this, I could then reference the tag elements like mnemonic and name with something like  $name=$xml->{$table}->{name};.

In reply to using xml::simple with unknown xml structure by ctaustin

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.