ok...following the instructions, this is what i came up with
<?php
$team_names = array();
$flag = '';
$count = 0;
function opening_element($parser, $element, $attributes)
{
// opening XML element callback function
global $flag;
if ($element == 'name')
$flag = $attributes['type'];
}
function closing_element($parser, $element)
{
// closing XML element callback function
global $flag;
if ($element == 'name')
$flag = '';
}
function character_data($parser, $data)
{
// callback function for character data
{
global $flag;
if ($flag=='')
{
global $team_name;
$team_name[] = $data;
}
}
}
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, 'opening_element','closing_element');
xml_set_character_data_handler($parser, 'character_data');
$document = file('team_id');
foreach ($document as $line)
{
xml_parse($parser, $line);
}
xml_parser_free($parser);
printf("Teams :\n");
foreach ($team_name as $team_name)
{
$count++;
printf("%s \n", $team_name);
}
?>
It works, but it doesnt extract the exact part of data which i want...the xml files dont have attributes which is why i cant use them to loacate the exact part i want to tabulate. This is a small piece of what the xml file looks like
<?xml version="1.0"encoding="iso-8859-1"?>
<teams>
<team>
<id>2</id>
<name>Master StrategyGroup</name>
<total_credit>28122.746859</total_credit>
<expavg_credit>1800.834974</expavg_credit>
<expavg_time>1089782608.779980</expavg_time>
<nusers>158</nusers>
</team>
<team>
<id>3</id>
<name>El Reg</name>
<total_credit>34278.850596</total_credit>
<expavg_credit>2190.886998</expavg_credit>
<expavg_time>1089781057.732820</expavg_time>
<nusers>408</nusers>
</team>
<team>
<id>4</id>
<name>Taldren</name>
<total_credit>4722.024311</total_credit>
<expavg_credit>239.961678</expavg_credit>
<expavg_time>1089778903.247760</expavg_time>
<nusers>163</nusers>
</team>
<team>
<id>5</id>
<name>Spot_E.T.</name>
<total_credit>22712.357342</total_credit>
<expavg_credit>1361.877631</expavg_credit>
<expavg_time>1089782181.841040</expavg_time>
<nusers>173</nusers>
</team>
</teams>
I want to be able to extract each part of each team (eg. id, name, nusers,etc.) and sort & tabulate it.