Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This code worked for me (using OO interface):
#!/usr/bin/perl use strict; use XML::Simple; use Data::Dumper; my $xml_obj = XML::Simple->new(ForceArray => ['tables']); # xml my $xml = $xml_obj->XMLin('test.xml'); print Dumper($xml); exit;
Also, double check for any errors in your xml file.

Output:
$VAR1 = { 'detail' => { 'rate' => { 'name' => 'RATE', 'type' => 'number', 'size' => '', 'mnemonic' => 'rate' }, 'date' => { 'name' => 'The_Date', 'type' => 'date', 'size' => '8', 'mnemonic' => 'date' }, 'name' => 'schema.detail', 'requiredfields' => 'date,rate,scenarioname' }, 'junk1' => { 'name' => 'rates', 'requiredfields' => 'date,rate', 'type' => 'junk1' }, 'junk2' => { 'name' => 'demands', 'requiredfields' => '', 'type' => 'junk2' }, 'xyz' => { 'cpr' => { 'required' => 'true', 'calc' => 'CASE WHEN SUM(a) != 0 THEN roun +d((1-power(1-sum(b/100*a)/sum(a),12))*100,2) ELSE SUM(0) END', 'name' => 'CPR', 'cohort' => 'false', 'type' => 'summed', 'size' => '8', 'mnemonic' => 'cpr' }, 'obsdate' => { 'required' => 'false', 'calc' => 'to_char(asofdate,\'mm/dd/yy +yy\')', 'name' => 'asofdate', 'cohort' => 'true', 'type' => 'summed', 'size' => '8', 'mnemonic' => 'obsdate' }, 'model' => { 'required' => 'true', 'calc' => 'trim(\'model\')', 'name' => 'model', 'cohort' => 'true', 'type' => 'summed', 'size' => '', 'mnemonic' => 'model' }, 'name' => 'schema.xyz', 'requiredfields' => 'obsdate,wac,wala,wam', 'loancount' => { 'required' => 'false', 'calc' => 'sum(LOANCOUNT)', 'name' => 'LoanCount', 'cohort' => 'fale', 'type' => 'summed', 'size' => '8', 'mnemonic' => 'loancount' }, 'new' => { 'required' => 'false', 'name' => 'ISNEW', 'cohort' => 'true', 'type' => 'char', 'size' => '', 'mnemonic' => 'new' } } };

Code w/ loop:
#!/usr/bin/perl use strict; use XML::Simple; use Data::Dumper; my $xml_obj = XML::Simple->new(ForceArray => ['tables']); # xml my $xml = $xml_obj->XMLin('test.xml'); for my $table (keys %$xml) { print Dumper($table); } exit;

In reply to Re: using xml::simple with unknown xml structure by shiza
in thread 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-26 05:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found