PHP Parse XML and sort Child Nodes alphabetically

initwosmoma

New Member
I have an XML file and parse it into my PHP document. I want to order the child nodes of my XML in an alphabetical order and show them in my select box. Can someone please help me? I'm stuck in the sorting process... :)country.xml\[code\] <?xml version="1.0"?><countries> <country> <name>Deutschland</name> <league>Bundesliga</league> </country> <country> <name>Frankreich</name> <league>Ligue 1</league> </country> <country> <name>Osterreich</name> <league>Tipp3-Bundesliga</league> </country> <country> <name>England</name> <league>Premier League</league> </country> <country> <name>Schweden</name> <league>Allsvenskan</league> </country> <country> <name>Kanada</name> <league>Canadian Soccer League</league> </country></countries>\[/code\]My PHP code looks as follows:\[code\]echo "<select>"; foreach ($newXml as $item) { $country=$item->name; $league=$item->league; echo $league; echo "<option>".$country."-".$league."</option>";} echo "</select>";\[/code\]
 
Back
Top