FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

problem with hash from Perl XML::Simple

 


stone1343
Hi, I'm trying to use XML::Simple to parse an XML file (which happens to have genealogy data - generated by GED2XML)

I then use Data::Dumper to print everything, but I can't figure out where to go from here. It's not specific to XML::Simple, it's understanding hashes. I see this for one person, but can't figure out how to access it by ID, given that I don't know the IDs in advance. I even understand the structure: 'change', 'id' are keys.

I think part of what I don't understand is why am I using $data instead of %data, when it returns a hash? How can I traverse to find all the IDs of all the people, and work with them?

Hope the question & solution are clear enough to you...

Thanks

{
'change' => '2006-10-25T12:22:52',
'id' => 'P4',
'sex' => 'male',
'personalname' => {
'np' => [
{
'content' => 'George',
'tp' => 'unkw'
},
{
'content' => 'Bush',
'tp' => 'surn'
}
]
}
}

Here's the relevant code:

# create object
$xml = new XML::Simple(KeyAttr=>"");

# read XML file
$data = $xml->XMLin("jmsdown.gml");
print Dumper($data);

$people = $data->{person};
print Dumper($people);
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.