PHP DOM XML Attribute alphabetisch Sortieren
Hallo,
ich möchte gern ein DOM Document Array alphabetisch sortieren, wie es bei einem normalem Array() geht weiß ich, allerdings bin ich bei DOM überfragt.
PHP Code:
$valueName soll alphabetisch sortiert werden
$valueName sind einfach Usernamen.
Vielen Dank für jegliche Hilfe
ich möchte gern ein DOM Document Array alphabetisch sortieren, wie es bei einem normalem Array() geht weiß ich, allerdings bin ich bei DOM überfragt.
PHP Code:
$xml = new DOMDocument();
$xml ->load( 'files/xml/usermasterlist.xml', LIBXML_NOBLANKS);
$xml ->formatOutput = true;
$element = $xml ->getElementsByTagName('DataID');
$valueName = $element->getAttribute('name');
$valueName soll alphabetisch sortiert werden
$valueName sind einfach Usernamen.
Vielen Dank für jegliche Hilfe
Please also mark the comments that contributed to the solution of the article
Content-Key: 273012
Url: https://administrator.de/contentid/273012
Printed on: April 26, 2024 at 03:04 o'clock
2 Comments
Latest comment
http://stackoverflow.com/questions/10528287/how-to-sort-a-xml-file-usin ...
Gruß jodel32
<?php
$xmlpath = "test.xml";
$dom = new DOMDocument();
$dom->load($xmlpath);
$nodelist = $dom->getElementsByTagName('DataID');
function sort_via_name_attribute($a,$b){
return strnatcmp($a->getAttribute('name'),$b->getAttribute('name'));
}
$nodes = iterator_to_array($nodelist);
usort($nodes,'sort_via_name_attribute');
foreach($nodes as $node){
echo $node->getAttribute('name'). '<br>';
}
?>