Parse XML from File with Attributes (php)
I need to parse an XML file using PHP.
I have found tutorials that show how to load the file and also how to parse it with attributes, but no one puts the two together.
I understand that to load the file, I write: $xml = simplexml_load_file('file开发者_如何学JAVAname.xml');
The format of the xml file is such that the information I want is within tags. ex:
<match date="April 19, 2011" timezone="EST" status="Final" time="8:00 PM" formatted_date="19.04.2011" id="7342">
Let's say I want the date.
When I read about parsing xml with PHP I would expect to write:
$date = match->attributes()->date;
but this just returns an empty result. I can't figure out how to link it with the file. In other words - how do I link the above line of code with $xml to get the content I want out of the file?
Thanks in advance, John
I swear to God, if you do REGEX PARSING to try to pull out attribute values of a structured document YOAR DOING IT WRONG!
Rather than "parsing", you probably want to use the DOMNode API to traverse the document using a query (written in XPATH) to find what you're looking for.
精彩评论