Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I have an XML file of members in a costuming organization. I'd like to be able to sort this data variably sometimes on based on last name (with secondary sorting on first name), and other times based on member number (TKID, not USERID below). The XML looks like this.
[syntax="xml"]
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="member_test.xsl"?>
<garrison>
<members>
<member>
<first>John</first>
<last>Doe</last>
<tkid>100</tkid>
<costume>TK</costume>
<costume>BH</costume>
<userid>2545</userid>
</member>
<member>
<first>Joe</first>
<last>Blow</last>
<tkid>148</tkid>
<costume>BH</costume>
<costume>TK</costume>
<costume>TB</costume>
<userid>2612</userid>
</member>
<member>
<first>Jane</first>
<last>Doe</last>
<tkid>101</tkid>
<costume>TK</costume>
<userid>2612</userid>
</member>
</members>
</garrison>
I'm using PHP4. Here is the code I'm using to parse.[/syntax]
Code: Select all
<?php
class xml_member{
var $first, $last, $tkid, $userid;
var $costume = array();
}
// this function handles each opening XML tag. example: <costume>
function startTag($parser, $data){
global $current_tag;
$current_tag .= "*$data";
}
// this function handles each closing XML tag. example: </costume>
function endTag($parser, $data){
global $current_tag;
$tag_key = strrpos($current_tag, '*');
$current_tag = substr($current_tag, 0, $tag_key);
}
// this function handles the data between opening and closing tags.
function contents($parser, $data){
global $current_tag, $xml_first_key, $xml_last_key, $xml_tkid_key, $xml_userid_key, $xml_costume_key, $counter, $member_array;
switch($current_tag){
case $xml_first_key:
$member_array[$counter] = new xml_member();
$member_array[$counter]->first = $data;
break;
case $xml_last_key:
$member_array[$counter]->last = $data;
break;
case $xml_tkid_key:
$member_array[$counter]->tkid = $data;
break;
case $xml_costume_key:
$member_array[$counter]->costume[] = $data;
break;
case $xml_userid_key:
$member_array[$counter]->userid = $data;
$counter++;
break;
}
}As you can see, the relevant data for, lets say the last name, end up in $member_array[$counter]->last
Can someone reply with code that will alternately sort $member_array based on last name (with secondary sort on first), and on TKID?
PS: Please forgive me if my code is crap, I'm still learning, and without proper instruction.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]