/    Sign up×
Community /Pin to ProfileBookmark

Sorting XML With PHP

I have an xml file that I am extracting the text of articles from.

The structure is as follows:

<?xml version=”1.0″ encoding=”ISO-8859-1″?>

<articles>

<article>
<title></title>
<date></date>
<author></author>
<id></id>
<url></url>
<type><type>
<position></position>
<summary></summary>
<text></text>
</article>

</articles>

I want to output them sorted by date. Any advice?

<?php
$xml = simplexml_load_file(“data/data.xml”);

foreach($xml as $user)
{
echo $user->text;
}

?>

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@sstalderAug 29.2008 — You would have to apply an XSL template to it before writing the output.
Copy linkTweet thisAlerts:
@acorbelliAug 29.2008 — You could use an XSL Template and XSL transformations to XML or HTML to do the sorting, or you could write a routing that stores each <article> as an object and then set up an array of these objects, sort them by date, and then output them.

The first way is obviously easier, but whatever floats your boat.
×

Success!

Help @whYunderground spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...