Codice PHP per ordinare i tag XML in ordine alfabetico?

Il text XML originale:

<a> <ccc /> <bb></bb> <d> <ff /> <eee /> </d> </a> 

Dopo l'sorting, dovrebbe essere:

 <a> <bb /> <ccc /> <d> <eee /> <ff /> </d> </a> 

Se conosci un bel modo per farlo, per favore mostramelo. Grazie!

Può essere fatto ad esempio tramite il module XSL di php

 <?php $xsl = new XSLTProcessor(); $xsl->importStyleSheet( getDoc(getStylesheetData()) ); $doc = getDoc( getDocData() ); echo $xsl->transformToXML($doc); function getDoc($s) { $doc = new DOMDocument; $doc->loadxml($s); return $doc; } function getStylesheetData() { return <<< eox <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="iso-8859-1" indent="yes"/> <xsl:strip-space elements="*" /> <xsl:template match="@* | node()"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates select="node()"> <xsl:sort select="name()"/> </xsl:apply-templates> </xsl:copy> </xsl:template> </xsl:stylesheet> eox; } function getDocData() { return <<< eox <a> <ccc /> <bb></bb> <d> <ff /> <eee /> </d> </a> eox; } 

stampe

 <?xml version="1.0" encoding="iso-8859-1"?> <a> <bb/> <ccc/> <d> <eee/> <ff/> </d> </a>