pascallantzsch
Goto Top

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:
$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 face-smile

Content-Key: 273012

Url: https://administrator.de/contentid/273012

Printed on: April 18, 2024 at 03:04 o'clock

Mitglied: 114757
Solution 114757 May 27, 2015 updated at 10:32:42 (UTC)
Goto Top
http://stackoverflow.com/questions/10528287/how-to-sort-a-xml-file-usin ...

<?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>';  
}
?>
Gruß jodel32
Member: pascallantzsch
pascallantzsch May 27, 2015 at 16:27:39 (UTC)
Goto Top
Jodel du bist heut mein persönlicher Held. Danke face-smile