...

View Full Version : re-sorting parts of an xml



fatmess
03-07-2009, 09:58 PM
Hi,
beginner question,
I want to re-sort an xml file at the beginning of my php file.
Let's say for example my xml looks like this;


<zoo>
<park one>
<cow>Friesian</cow>
<dog>Labrador</dog>
<sheep>Barbados Blackbelly</sheep>
<horse>Shire</horse>
</park one>
<park two>
<cow>Jersey</cow>
<dog>Doberman</dog>
<sheep>Debyshire Gritstone</sheep>
<horse>Spanish Mustang</horse>
</park two>
</zoo>

I would like to re-sort it in my php routine just for use in this routine to;


<zoo>
<park one>
<sheep>Barbados Blackbelly</sheep>
<horse>Shire</horse>
<dog>Labrador</dog>
<cow>Friesian</cow><horse>Shire</horse>
</park one>
<park two>
<sheep>Derbyshire Grritstone</sheep>
<horse>Spanish Mustang</horse>
<dog>Doberman</dog>
<cow>Jersey</cow><horse>Shire</horse>
</park two>
</zoo>

Therefore cow, dog sheep horse to sheep horse dog cow.
I'd prefer not to use an xslt file and do it with php if possible
Thanks for any help.

sea4me
03-08-2009, 06:41 AM
This will help:

http://us2.php.net/manual/en/book.simplexml.php

You would get all the options into variables and then reorder them and finally print them :)
Good Luck! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum