Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    re-sorting parts of an xml

    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;

    Code:
    <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;

    Code:
    <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.

  • #2
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •