Hello Monks,
I'm using XML::Simple to parse XML that is similar to the following in order to look at various attributes within the <attributes> elements given below. The problem is that Data::Dumper converts the name="varyingName" values into elements.
I can't figure out how to get to the elements that are located further down the XML code tree given this name-to-element conversion behavior.
<dataschemas>
<dataschema name="varyingName1"
<attributes>
<attribute>
... some attributes ...
</attribute>
</attributes>
<dataschema name="varyingName2"
<attributes>
<attribute>
... some attributes ...
</attribute>
</attributes>
</dataschema>
</dataschemas>
Dumper produces output similar to the following snippet:
{
'dataschemas' => {
'dataschema' => {
'varyingName1' => {
'attributes' => {
'attribute' => {
... attributes here ...
}
}
},
'varyingName2' => {
'attributes' => {
'attribute' => {
... attributes here ...
}
}
}
}
}
}
Again, I don't know how to walk down the element (tree?) to get into the "attributes here" area. Since the 'varyingName' (elements?) change, I can't identify them directly. Please help! I've tried the following with no success:
To get to the first 'varyingName' stanza --
foreach my $d (@{$data->{dataschemas}->{dataschema}->[0]->{attributes}->{attribute}}) { ... do something here ... }
Now, something like the following does produce output:
print $data->{dataschemas}->{dataschema}->{varyingName1}->{attributes}->{attribute}->{name};
I went through the XML::Simple doc, searched this site, and Googled for other places to find the answer no luck so far. I'll greatly appreciate whatever assistance, insight, and wisdom you can provide to enable me to solve this problem.
Thank you, BW