element22 has asked for the wisdom of the Perl Monks concerning the following question:
I have a simple XML file:
<?xml version="1.0" encoding="Windows-1252"?> <App> <node name="1st node" text="Text of 1st node" /> <node name="2nd node" text="Text of 2nd node" /> <node name="3rd node" text="Text of 3rd node" /> ... </App>
I want to use XML::Simple to list all the "nodes" and their "text" attributes as follows:
1st node: Text of 1st node 2nd node: Text of 2nd node 3rd node: Text of 3rd node ...
What I have doesn't work, I get no listing at all:
use XML::Simple; use Data::Dumper; my $input="app.xml"; my $xml = new XML::Simple(KeyAttr =>1,ForceArray =>1); my $data = $xml->XMLin($input); foreach my $node (@{$data->{App}{node}}) { print $node->{name}.": ".$node->{text}."\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::Simple: list all element attributes
by frozenwithjoy (Priest) on Apr 08, 2015 at 06:03 UTC | |
by element22 (Novice) on Apr 08, 2015 at 06:32 UTC | |
by frozenwithjoy (Priest) on Apr 08, 2015 at 07:50 UTC | |
by element22 (Novice) on Apr 08, 2015 at 10:41 UTC | |
|
Re: XML::Simple: list all element attributes
by choroba (Cardinal) on Apr 08, 2015 at 08:20 UTC |