in reply to Predefining complex data structures?

I can't think of a single good reason to do this, as the data structure returned by XML::Simple should work for just about any need you have:
$VAR1 = { 'requirement' => [ { 'contactname' => 'Joe Average', 'content' => 'A power cord.' }, { 'contactnumber' => '555-1212', 'contactname' => 'Jane Smith', 'content' => 'A node name' } ] };
But, since you asked, how about this:
use strict; use XML::Simple; my $data = do {local $/;<DATA>}; my $xml = XMLin($data,forcearray=>1); my $new; for my $req (@{$xml->{requirement}}) { my %temp; $temp{text} = delete $req->{content}; $temp{attributes} = [%$req]; push @{$new->{requirements}}, {%temp}; } __DATA__ <xml> <requirement contactname="Joe Average">A power cord.</requirement> <requirement contactname="Jane Smith" contactnumber="555-1212">A node +name</requirement> </xml>
This produced the following data structure for me:
$VAR1 = { 'requirements' => [ { 'text' => 'A power cord.', 'attributes' => [ 'contactname', 'Joe Average' ] }, { 'text' => 'A node name', 'attributes' => [ 'contactnumber', '555-1212', 'contactname', 'Jane Smith' ] } ] };
UPDATE:
Woah! Sorry Ionizor, i read your post and parsed XML::Parser as XML::Simple. Forgive me, that's what i get for trying to answer questions in the morning without the prerequisite cup 'o joe first. :) But yes, XML::Simple will parse that XML snippet you provided:
$VAR1 = { 'method' => [ { 'object' => [ 'Properties', 'Do not use option Foo', 'Server Name', 'OK' ], 'content' => [ 'Open up the ', ' page. Then uncheck the ', ' checkbox. Under ', ' enter ', ' and then hit ' ], 'input' => [ 'www.example.com' ] } ] };
But that probably will not work for you. :(

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
(Ionizor) Re: Predefining complex data structures?
by Ionizor (Pilgrim) on Jul 12, 2002 at 15:19 UTC

    At the moment I'm using XML::Parser because I wasn't sure if XML::Simple would correctly handle things like:

    <method>Open up the <object>Properties</object> page. Then uncheck the <object>Do not use option Foo</object> checkbox. Under <object>Server Name</object> enter <input>www.example.com</input> and then hit <object>OK</object></method>

    Which I will be processing a little later on in the script.