Please help me with this - I need a class to parse XML data into a nested array.
In my class, I've started with:
php Code:
Original
- php Code |
|
|
|
This gives me two arrays in $_xml_values and $_xml_index in the class.
But I don't know how to re-struct these into a third array, that should be nested as the XML document.
Let's say the XML data looks like this:
php Code:
Original
- php Code |
|
|
|
<?xml version="1.0" encoding="ISO-8859-1"?>
<root>
<request>
<command>get_users</command>
<client>1.0</client>
</request>
<users>
<user type="admin">
<user_id>test_admin</user_id>
<skills>none</skills>
</user>
<user type="hangaround">
<user_id>loser</user_id>
<skills>very none</skills>
</user>
</users>
</root>
...then I would like the outcoming array to look like this:
php Code:
Original
- php Code |
|
|
|
[root]
{
[request]
{
[command]
{
[_value] => 'get_users';
}
[client]
{
[_value] => '1.0';
}
}
[users]
{
[user]
{
[_attributes]
{
[_type] => 'admin':
}
[user_id]
{
[_value] => 'test_admin';
}
[skills]
{
[_value] => 'none';
}
}
[user]
{
[_attributes]
{
[_type] => 'hangaround':
}
[user_id]
{
[_value] => 'loser';
}
[skills]
{
[_value] => 'very none';
}
}
}
}
The "Improved XML To Array" @ http://codewalkers.com/seecode/185.html doesn't work for me, and I would like to know how things work - not just copy. We're here to learn, right?
Very greatful for help!