Hello everyone, i am a newbee and i am totally lost on sorting with simplexml
I am working with the Simple XML class and i am trying to figure out how to sort the actual elements on the XML list so that the next time i open the xml file the elements have been sorted according to an attribute 'id'
<code>
///////XML FILE
<?xml version="1.0" encoding="ISO-8859-1"?>
<holdAll>
<wonder id="4">fourth</wonder>
<wonder id="2">Second</wonder>
<wonder id="3">Third</wonder>
<wonder id="1">First</wonder>
</holdAll>
/////PHP ////////////
$xml = simplexml_load_file('getThis.xml');
function sortById($xml)
{
foreach($xml->wonder as $item)
{
Sort($item['id']); ///I have no idea how to do this...I want all the items to sort by the id number i
///on the actual XML file.
}
}
$xml->asXML('getThis.xml')
</code>
Sorting an XML file using SimpleXML?
Moderator: General Moderators
-
imsoconfused
- Forum Newbie
- Posts: 15
- Joined: Mon Oct 05, 2009 10:55 pm