The following code successfully parses the xml file:<config> <wrapper name="testName 1.0.3" script="/usr/people/ltorvalds/apps/ +wrapper.pl" app="testApp.exe"> <envVar name="TMPDIR" value="/usr/tmp"/> <envVar name="APPDIR" value="/usr/bin"/> </wrapper> </config>
... and correctly produces the following output ...#!/usr/bin/perl -w use XML::Simple; my $ref = XMLin(); my $wrapName = "testName 1.0.3"; print "$ref->{wrapper}->{$wrapName}->{script}\n"; print "$ref->{wrapper}->{$wrapName}->{envVar}->{TMPDIR}->{value}\n";
Now, if I try to treat the <envVar> tags as an array, I run into trouble:/usr/people/ltorvalds/wrapper.pl /usr/tmp
... produces a blank line. I assumed that this was because I needed to turn forceArray on, so I changed the call to XMLin():print "$ref->{wrapper}->{$wrapName}->{envVar}->[0]->{value}\n";
... but still I get the same blank line as output.my $ref = XMLin(xmlTest.xml, forceArray=>['envVar']);
I suspect that I'm either using forceArray incorrectly or I'm using an invalid array reference. Any insight as to where my folly lies would be appreciated.
Thanks for all of the input. What have I learned? I have learned that I need to:
In reply to How do I correctly use arrays with XML::Simple? by ccarden
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |