Web Analytics Made Easy -
StatCounter sorting xml data by fields - CodingForum

Announcement

Collapse
No announcement yet.

sorting xml data by fields

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • sorting xml data by fields

    Hi All,

    i have an xml file which i need to sort by various fields depending on what the user selects, ie: release date, name, popularity but im not sure how to sort the xml file?

    can anyone help please


    EDIT
    ====

    i found this great script which seems to be exactly what i after but as my xml is very large it runs out of memory and fais to sort the xml file

    any ideas of a way around this?

  • #2
    Sort XML file using PHP

    I hope this help you:

    Code:
    $string = <<<EOS
    <page>
    <talentTrees>
    <tree name="Football" order="2" />
    <tree name="Baseball" order="0" />
    <tree name="Frisbee" order="1" />
    </talentTrees>
    </page>
    EOS;
    
    $xml = simplexml_load_string($string);
    
    $trees = $xml->xpath('/page/talentTrees/tree');
    function sort_trees($t1, $t2) {
        return strcmp($t1['order'], $t2['order']);
    }
    
    usort($trees, 'sort_trees');
    var_dump($trees);
    Don't forget to mark solution providing post as "Answered".
    It helps others to find correct solutions!

    Comment


    • #3
      xml data

      are you looking to edit the xml file? If so you could try using a large file xml editor, I have also posted a link below to a free large file xml editor that can cope with GB and even TB files.

      http://www.liquid-technologies.com/D...FileEditor.zip

      Comment

      Working...
      X