Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

parsing XML structure

by frustrateduser (Initiate)
on Mar 30, 2012 at 13:50 UTC ( #962612=perlquestion: print w/replies, xml ) Need Help??

frustrateduser has asked for the wisdom of the Perl Monks concerning the following question:

Trying to figure out how to get data out of this structure using XML::simple (or anything else for that matter!). Note: this is the output coming from debug:
DB<15> x $file 0 'ecfc_ECFC_ModuleUserSetting.xml' DB<16> x $data 0 HASH(0x391b010) 'ecfc_ECFC_ModuleUserSetting' => ARRAY(0x391b5a0) 0 HASH(0x3b10fb0) 'createdOn' => '2012-02-23T17:40:04' 'modifiedOn' => '2012-02-23T17:40:20' 'moduleId' => '{6FE8AD18-9C50-4DC1-A3A0-5DE169056453}' 'propertyData' => '<HelloWorldUserSettings xmlns:xsd="http:// +www.w3.org /2001/XMLSchema"><Theme>default</Theme><Message>ll</Message></HelloWor +ldUserSett ings>' 'userId' => '{FA8A7172-5C01-491A-8DC6-F4FDC9341795}' 1 HASH(0x3b101c8) 'createdOn' => '2012-01-17T17:38:17' 'moduleId' => '{18B3146E-4995-462C-BD0F-5E8E0359A00E}' 'propertyData' => '<HelloWorldUserSettings xmlns:xsd="http:// +www.w3.org /2001/XMLSchema"><Theme>default</Theme><Message>Luke</Message></HelloW +orldUserSe ttings>' 'userId' => '{FA8A7172-5C01-491A-8DC6-F4FDC9341795}' 'generated' => '2012-03-28T15:21:38' 'xmlns:od' => 'urn:schemas-microsoft-com:officedata' 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance' 'xsi:noNamespaceSchemaLocation' => 'ecfc_ECFC_ModuleUserSetting.xsd +'

Replies are listed 'Best First'.
Re: parsing XML structure
by temporal (Pilgrim) on Mar 30, 2012 at 15:25 UTC

    It looks like you've already parsed the XML file using XML::Simple, which returns a hash.

    However, it has been saved using Excel (or something), which probably adds a bunch of metadata to the file. That's all the crap you're seeing there.

    You'll want to open the actual XML data of the file which is hidden away in the 'propertyData' field. Split between 2 of them for some reason. Odd.

    From your debug - a hash, containing an array, containing another hash. lol.

    $actualXML0 = $data->{ecfc_ECFC_ModuleUserSetting}->[0]->{propertyData +}; $actualXML1 = $data->{ecfc_ECFC_ModuleUserSetting}->[1]->{propertyData +}; $actualData0 = XMLin($actualXML0); $actualData1 = XMLin($actualXML1);

    As for accessing the data from there... XML::Simple

Re: parsing XML structure
by grantm (Parson) on Mar 31, 2012 at 02:23 UTC

    If you're unclear on how to extract data from nested hashes and arrays, perhaps Mark's very short tutorial about references would be a good place to start. Viewing the output using Data::Dumper (or YAML or JSON with pretty formatting turned on) would probably give a clearer illustration of the structure.

    If you're new to XML::Simple I recommend reading up on how to avoid common pitfalls as well as one suggestion on a better module to use.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://962612]
Approved by Eliya
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2019-12-11 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?