I'm reading in an xml file,
$myxml = XMLin("$configfile");
And when I print it using Dumper (print Dumper($myxml);) I get this...
$VAR1 = {
'Timeout' => 5,
'Roots' => {
'Root' => [
{
'Name' => 'Sales',
'Level' => 'Indeterminate',
'Profiles' => {
'Profile' => [
{
'Name' => 'Bill',
'Age' => '50',
'Status' => Active
},
{
'Name' => 'Bob',
'Age' => '24',
'Status' => Inactive
}
]
},
'Interval' => 'Order',
'Action' => 'Reject'
},
{
'Name' => 'User',
'Level' => 'Indeterminate',
'Profiles' => {
'Profile' => [
{
'Name' => 'User',
'Action' => 'Reject',
'User' => 'acount'
},
{
'Name' => 'Admin',
'Action' => 'Accept',
'User' => 'acount'
},
]
}
};
I'd like to read this hash and get the value of all inactive 'Status' or or get 'Bob's Status..
{
'Name' => 'Bob',
'Age' => '24',
'Status' => Inactive
}
Start Edit:
So to get profile information for one person..
Dumper($myxml->{'Roots'}->{'Root'}[0]{'Profiles'}{'Profile'}[2]);
For example to get the Status for Bob
if ($myxml->{'Roots'}->{'Root'}[0]{'Profiles'}{'Profile'}[1]{'Name'} eq "Bob") {
$status = $myxml->{'Roots'}->{'Root'}[0]{'Profiles'}{'Profile'}[1]{'Status'};
}
However, how do I loop through this xml so it will keep checking {'Roots'}->{'Root'} and {'Profiles'}{'Profile'} in case Bob is not in location [0] and [1]. A double foreach loop?
End Edit
I've included an example of the xml..
<Root Name="Sales" Level="Indeterminate" Profile="Order" Interval="Order" Action="Reject">
<Profiles>
<Profile Name="Bill" Age="50" Status=Active />
<Profile Name="Bob" Age="24" Status=InActive />
<Profile Name="Ben" Age="45" Status=Active />
</Profiles>
</Root>
Which produces this:
$VAR1 = {
'Name' => 'Sales',
'Type' => 'Indeterminate',
'Profiles' => {
'Profile' => [
{
'Name' => 'Bill',
'Age' => '50',
'Status' => Active
},
{
'Name' => 'Bob',
'Age' => '24',
'Status' => InActive
},
{
'Name' => 'Ben',
'Age' => '45',
'Status' => Active
}
]
},
'Interval' => 'Order',
'Action' => 'Reject'
};
Thanks,
John.