Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335858
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:04:01+00:00 2026-05-18T00:04:01+00:00

I have tried to get an XML file to sort and have had no

  • 0

I have tried to get an XML file to sort and have had no luck. After a day and a-half, I need some help from an expert. Thanks.

My XML File (shortened for the example):

<?xml version="1.0" encoding="iso-8859-1"?>
<deadlines>
    <deadline>
        <date>2010-06-01</date>
        <text>Application for Summer Due</text>
    </deadline>
    <deadline>
        <date>2010-07-01</date>
        <text>Application for Fall Due</text>
    </deadline>
    <deadline>
        <date>2010-07-31</date>
        <text>Summer Bill Due</text>
    </deadline>
</deadlines>

My PHP:

<?php

$xml = simplexml_load_file($_SERVER['DOCUMENT_ROOT'].'/feeds/deadlines.xml');

// start THIS WORKS
echo'<pre>';
foreach($xml as $deadline) echo <<<EOF
    Date: {$deadline->date}
    Text: {$deadline->text}


EOF;
echo'</pre>';
// end THIS WORKS

?>

Does anyone have a simple PHP solution to sort the XML file on “date” prior to the echo to screen?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:04:01+00:00Added an answer on May 18, 2026 at 12:04 am

    Okay, sorry for going around the houses before – I’ve added a different answer for clarity but using the sort proxying technique I linked to.

    function xsort(&$nodes, $child_name, $order=SORT_ASC)
    {
        $sort_proxy = array();
    
        foreach ($nodes as $k => $node) {
            $sort_proxy[$k] = (string) $node->$child_name;
        }
    
        array_multisort($sort_proxy, $order, $nodes);
    }
    
    $structure = '<?xml version="1.0" encoding="utf-8" ?>
    <deadlines>
        <deadline>
            <date>2010-06-01</date>
            <text>Application for Summer Due</text>
        </deadline>
        <deadline>
            <date>2010-07-01</date>
            <text>Application for Fall Due</text>
        </deadline>
        <deadline>
            <date>2010-07-31</date>
            <text>Summer Bill Due</text>
        </deadline>
    </deadlines>';
    
    $xml = simplexml_load_string($structure);
    $nodes = $xml->xpath('/deadlines/deadline');
    
    // Sort by date, descending
    xsort($nodes, 'date', SORT_DESC);
    var_dump($nodes);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tried to get some information from W3C regarding the update of an
I have this XML file I need to extract the HTML Code from mono
I have an XML file that I need to sort. Worked great until the
I have tried using date(m/d/Y, strtotime(04-05-2012)) but I will get 05/04/2012 or on some
I need to get the package name of an Android APK. I have tried
I have been trying for about a day now to get an xml feed
I want to generate xml file from Struts action object. So that I have
I have tried using the below code modified from http://www.html5rocks.com/tutorials/file/dndfiles/ to read in a
I have a page that grabs content from a XML file through a Jquery
I am populating jQuery accordion from simple xml file, I can get my data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.