Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting XML feeds (e.g. by name)

Status
Not open for further replies.

dazza12345

Programmer
Nov 25, 2005
35
GB
HI all, just a quick questio: im new to all this xml stuff but am looking to use it for my site. I have been able to find a good tutorial that has been able to tell me how to output the content of an XML file, this is shown bellow:

<?php

$insidetourno = false;
$tag = "";

$tournoID = "";
$tournoname = "";
$tournotype = "";
$gametype = "";
$tournolimit = "";
$tournoenrolled = "";
$tournomaxplayers = "";
$tournofee = "";
$tournoprize = "";
$tournotime = "";

function startElement($parser, $name, $attrs) {
global $insidetourno, $tag, $name1, $stake, $players, $averagepot, $playersflop, $handsperhour;

if ($insidetourno) {
$tag = $name;
}
elseif ($name == "TOURNAMENT") {
$insidetourno = true;
}
}


function endElement($parser, $name) {

global $insidetourno, $tag, $tournoID, $tournoname, $tournotype, $gametype, $tournolimit, $tournoenrolled, $tournomaxplayers, $tournofee, $tournoprize, $tournotime;

if ($name == "TOURNAMENT") {
echo $tournoID.$tournoname.$tournotype.$gametype.$tournolimit.$tournoenrolled.$tournomaxplayers.$tournofee.$tournoprize.$tournotime. '<br><br>';

$tournoID = "";
$tournoname = "";
$tournotype = "";
$gametype = "";
$tournolimit = "";
$tournoenrolled = "";
$tournomaxplayers = "";
$tournofee = "";
$tournoprize = "";
$tournotime = "";

$insidetourno = false;
}
}

function characterData($parser, $data) {
global $insidetourno, $tag, $tournoID, $tournoname, $tournotype, $gametype, $tournolimit, $tournoenrolled, $tournomaxplayers, $tournofee, $tournoprize, $tournotime;
if ($insidetourno) {
switch ($tag) {
case "TOURNAMENT-ID":
$tournoID .= $data;
break;
case "TOURNAMENT-NAME":
$tournoname .= $data;
break;
case "TOURNAMENT-TYPE":
$tournotype .= $data;
break;
case "GAME-TYPE":
$gametype .= $data;
break;
case "TOUR-LIMIT":
$tournolimit .= $data;
break;
case "ENROLLED":
$tournoenrolled .= $data;
break;
case "MAX-PLAYERS":
$tournomaxplayers .= $data;
break;
case "FEE":
$tournofee .= $data;
break;
case "GUARANTEED-PRIZE":
$tournoprize .= $data;
break;
case "SEATING-TIME":
$tournotime .= $data;
break;
}
}


}

$xml_parser = xml_parser_create();

xml_set_element_handler($xml_parser, "startElement", "endElement");

xml_set_character_data_handler($xml_parser, "characterData");

$fp = fopen(" or die("Error reading RSS data.");

while ($data = fread($fp, 4096))
xml_parse($xml_parser, $data, feof($fp))
or die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));

fclose($fp);

xml_parser_free($xml_parser);

?>


Is there any way of sorting the output of the XML file by different criteria e.g. tournament name, id, time, prize money etc.

Cheers
 
I would look at using XSL. Google for 'PHP XSL'

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top