So sortieren Sie eine XML-Datei mit DOM

Ich habe eine XML-Datei wie folgt aufgebaut

<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>

Um diese XML nach der Buch-ID zu sortieren,

nach der Überprüfungdiese Methode von Stackoverflow

Ich habe so codiert

<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>

Aber es gibt mir einen Fehler

Warnung: usort () erwartet, dass Parameter 1 ein Array ist, ein Objekt, das in /var/www/html/testphp/phpxml/readxml.php in Zeile 24 angegeben ist

Antworten auf die Frage(2)

Ihre Antwort auf die Frage