How to sort a xml file using DOM

allo

New Member
I have a xml file structured like\[quote\]\[code\]<?xml version="1.0"?> <library><book id="1003"> <title>Jquery MVC</title> <author>Me</author> <price>500</price></book><book id="1001"> <title>Php</title> <author>Me</author> <price>600</price></book><book id="1002"> <title>Where to use IFrame</title> <author>Me</author> <price>300</price></book></library>\[/code\]\[/quote\]In order to sort this xml according to the book id,after reviewing this method from stackoverflowi coded like this\[code\]$dom = new DOMDocument();$dom->load('DOM.xml');$library = $dom->documentElement;$xpath = new DOMXPath($dom);$result = $xpath->query('/library/book');function sort_trees($t1,$t2){ return strcmp($t1['id'], $t2['id']); }usort($result, 'sort_trees');print_r($result);*/\[/code\]But it gives me an error Warning: usort() expects parameter 1 to be array, object given in /var/www/html/testphp/phpxml/readxml.php on line 24Please help me on this problem??
 
Back
Top