Working with the SAX parser (I can't use the DOM - I'm on Windows), you can catch whatever attributes you're looking for inside the function you specify as the beginning element handler. You could write code similar to this:
*** PHP CODE ***
<?php
function startElement($parser, $name, $attrs) {
print "Element = $name<br>";
print "Attributes:<br>";
while(list($attr, $value) = each($attrs)) {
print "$attr = $value<br>";
}//end of while
}// end of startElement
function endElement($parser, $name) {
print "<br><br>";
}//end of endElement
function characterData($parser, $value) {
print "$value<br>";
}//end of characterData
$file = "easy.xml";
//Create the SAX parser
$parser = xml_parser_create();
//Disable case-folding
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
//setup the handlers
xml_set_element_handler($parser, "startElement", "endElement");
xml_set_character_data_handler($parser, "characterData");
//open the file
if(!($fp = fopen($file, "r"))) {
die("Could not open the XML file.");
}
//parse the XML
while ($data = fread($fp, 4096)) {
if (!xml_parse($parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code(
$parser)),
xml_get_current_line_number($parser)));
}
}
//Free up the memory associated with the XML parser.
xml_parser_free($parser);
//Close the XML file
fclose($fp);
?>
*** END OF PHP CODE***
*** easy.xml ***
<?xml version="1.0" standalone="yes"?>
<easy does="1" it="2">Some easy character data.</easy>
Your output in a browser will be:
Element = easy
Attributes:
does = 1
it = 2
Some easy character data.
If you need to process an attribute differently (e.g - you want to do something with the attribute 'it'), just write code inside the startElement() function to handle it. (e.g. if($attr == "it"){.....}).
I hope this helps somewhat.
Bart