Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Clobbered keys in XML::Simple

by Rhose (Priest)
on Aug 29, 2002 at 17:45 UTC ( #193838=note: print w/ replies, xml ) Need Help??

in reply to Clobbered keys in XML::Simple

What is happening here is that 'name' is one of the default key attributes for XML::Simple. (The defaults are 'name', 'key', and 'id'.) By changing this (with the keyattr option), I think you can get the desired results.

Here is a quick script I threw together which should demonstrate the differences. I hope it helps.

#!/usr/bin/perl -w use strict; use Data::Dumper; use XML::Simple; my $gXML; my $gXMLDoc; my $gXMLString; $/ = undef; $gXMLString = <DATA>; $gXML = XML::Simple->new(); $gXMLDoc = $gXML->XMLin($gXMLString); print 'Before:',"\n",'-' x 40,"\n",Dumper($gXMLDoc),"\n"; $gXMLDoc = $gXML->XMLin($gXMLString, keyattr => ''); print 'After:',"\n",'-' x 40,"\n",Dumper($gXMLDoc),"\n"; __DATA__ <DataContent> <head> <meta name="APU:IndustryCode" content="Banking / finance" /> <meta name="APU:IndustryCode" content="Joint ventures / investment" /> </head> </DataContent>

For more information on the options available with XML::Simple (forcearray is another one you will want to make sure you know), check out:

perldoc XML::Simple


Make sure you look at the data structure dumped with Data::Dumper -- meta is now a two element array.


The following code will iterate through the meta array:

foreach (0..$#{$gXMLDoc->{head}->{meta}}) { print $gXMLDoc->{head}->{meta}[$_]->{content},"\n"; }

Comment on Clobbered keys in XML::Simple
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://193838]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-09-30 19:04 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (381 votes), past polls