ctaustin has asked for the wisdom of the Perl Monks concerning the following question:
I have an xml file whose structure basically contains one known tag, the root, and several tags within this that are not known.
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:
<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:
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};.my $xml = XMLin($xfile,ForceArray=>1)||die("unable to perform 'in' n") +; foreach $table (keys %{$xml->{tables}}){ print "$table\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: using xml::simple with unknown xml structure
by shiza (Hermit) on Jul 14, 2005 at 16:15 UTC | |
by shemp (Deacon) on Jul 14, 2005 at 17:10 UTC | |
by ctaustin (Sexton) on Jul 14, 2005 at 19:57 UTC | |
Re: using xml::simple with unknown xml structure
by injunjoel (Priest) on Jul 14, 2005 at 17:50 UTC |
Back to
Seekers of Perl Wisdom