
August 1st, 2004, 09:26 PM
|
|
Contributing User
|
|
Join Date: May 2004
Location: Canada, Ontario
Posts: 131

Time spent in forums: 1 Day 5 h 11 m 41 sec
Reputation Power: 5
|
|
|
teamwarfare.com xml
I'm trying to parse the data contain in the xml link for a gaming clan
Link to xml btw the last 3 letters are @ss
another problem i ran into is I unsure how to display
tag's with the = included in the tag name.
( Example <ladder name="America's Army 2v2 Combat"> )
again another problem is geting the tag's that contain links to output as html links
below is what I gathered in code for php it displays some of the data from the xml but seems to mostly echo the tag data
can anyone code something up? it be a great help to the clans that use this rather then bashing there brains out like i have trying to understand this
Code:
<?
// arrays to associate XML elements with HTML output
$startTagsArray = array(
'TEAMINFORMATION' => '',
'NAME' => '<BR>NAME: ',
'URL' => '<BR>URL: ',
'EMAIL' => '<BR>EMAIL: ',
'STATUS' => '<BR>STATUS: ',
'FOUNDER' => '<BR>FOUNDER: ',
'DESCRIPTION' => '<BR>DESCRIPTION: ',
'COMPETITIONINFORMATION' => '<BR> ',
'HTTPLINK' => '<BR>HTTPLINK:',
'XMLLINK' => '<BR>XMLLINK: ',
'RANK' => '<BR>RANK: ',
'WINS' => '<BR>WINS: ',
'LOSSES' => '<BR>LOSSES:',
'FORFEITS' => '<BR>FORFEITS: ',
'MATCH STATUS' => '<BR>',
'OPPONENTNAME' => '<BR>OPPONENTNAME: ',
'HTMLLINK' => '<BR>HTMLLINK: ',
'XMLLINK' => '<BR>XMLLINK: ',
'MATCHDATE' => '<BR>MATCHDATE: ',
'MAP NAME' => '<BR>MAP NAME: ',
'PLAYER NAME' => '<BR>PLAYER NAME: ',
'JOIN DATE' => '<BR>JOIN DATE: ',
'POSION' => '<BR>POSION: ',
'HTMLLINK' => '<BR>HTMLLINK: '
);
$endTagsArray = array(
'LINE' => ','
);
// array to hold sub-totals
$subTotals = array();
// XML file
$xml_file = "http://www.teamwarfare.com/xml/viewteam_v2.asp?team=E%2DZ+Just+Kicked+Your+***";
// parse document
$doc = xmldocfile($xml_file);
// get the root node
$root = $doc->root();
// get its children
$children = $root->children();
// start printing
print_tree($children);
// this recursive function accepts an array of nodes as argument,
// iterates through it and:
// - marks up elements with HTML
// - prints text as is
function print_tree($nodeCollection)
{
global $startTagsArray, $endTagsArray, $subTotals;
foreach ($nodeCollection as $node)
{
// how to handle elements
if ($node->type == XML_ELEMENT_NODE)
{
// print HTML opening tags
echo $startTagsArray[strtoupper($node->tagname)];
// recurse
$nextCollection = $node->children();
print_tree($nextCollection);
// once done, print closing tags
echo $endTagsArray[strtoupper($node->tagname)];
}
// how to handle text nodes
if ($node->type == XML_TEXT_NODE)
{
// print text as is
echo($node->content);
}
// PI handling code would come here
// this doesn't work too well in PHP 4.1.1
// see the sidebar entitled "Process Failure"
// for more information
}
}
// this function gets the character data within an element
// it accepts an element node as argument
// and dives one level deeper into the DOM tree
// to retrieve the corresponding character data
function getNodeContent($node)
{
$content = "";
$children = $node->children();
return $content;
}
?>
|