This is the xml file. The code which is reading it is given below.<?xml version='1.0'?> <queries> <query> <name>topHosts</name> <layer>LINK</layer> <topN>20</topN> <datatype>topHosts</datatype> <filter></filter> </query> <query> <name>topHosts</name> <layer>LINK</layer> <topN>120</topN> <datatype>topHosts</datatype> <filter></filter> </query> </queries>
Result:$simple1 = XML::Simple->new(ForceArray=>1, KeepRoot=>1); $data1 = $simple->XMLin("query.xml"); print Dumper($data1) . "\n";
Now, I want to read the key elements (topN, layer, filter, name, datatype) values in different variables. But I did not find a any code which will read the above data structure and extract those values, looping through throught the number of queries. For example - code in this case should loop 2 times as you can see that there are two queries in the xml file (query.xml). Please help!$VAR1 = { 'queries' => [ { 'query' => [ { 'topN' => [ '20' ], 'layer' => [ 'LINK' ], 'filter' => [ {} ], 'name' => [ 'topHosts' ], 'datatype' => [ 'topHosts' ] }, { 'topN' => [ '120' ], 'layer' => [ 'LINK' ], 'filter' => [ {} ], 'name' => [ 'topHosts' ], 'datatype' => [ 'topHosts' ] } ] } ] };
In reply to XML parsing problem by avi_2009
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |