Gah! I've been going mad trying to figure this out today.
I have a small script that takes an XML document (by upload), parses the data between the tags using an XML class relying on SAX functions, and then saves the data in a variable to be used in my HTML templates.
What I'm trying to do though is grab an attribute (or more) from an element.
For example, here is the XML:
<?xml version="1.0"?>
<files>
<document type="mp3" created="10/19/03">
<title>My rock song</title>
<author>Solace D.</author>
</document>
</files>
Then the usage:
$xml_data = file_get_contents($_FILES['xmlfile']['tmp_name']);
$xml_parser = new XMLParser($xml_data);
$xml_parser -> fetchXML();
$author = $xml_parser -> fetchData("title"); // returns 'My Rock Song'
$document = $xml_parser -> fetchData("document");
echo $document['TYPE'];
Now, I would have thought [font=courier new]echo $document['TYPE'];[/font] (note it is upper-case sensitive) would return the attribute value mp3, but it doesn't! :o Most likely because I've screwed up on my syntax, and/or I need to modify stuff in my class.
If you know XML parse stuff, please give me some input. 😃
Attached is the class.
I'd rather not use the DOM XML functions, since I don't feel like converting over my class. (also DOM XML is said to be experimental)