ali_kiyani Posted September 23, 2008 Share Posted September 23, 2008 Hi, I want to read an XML file which can be reached here. http://www.mazda.ca/eng/Vehicles/Mazda3/sedan_content/Mazda3_subnav02_content04.xml I looked for XML parsers on Google and found several results which were using PHP Expat to do the job. One of them is this one: http://www.linkstraffic.net/programming/php/xml/xmlparser.php But I found out that to parse any XML file you must know its structure and tags. That is each parsers will be tailor made to read that particular XML file. Now my questions are: 1. Is there a generic parser available that will read all nodes and data? 2. Looking at the XML file above which I want to read can you suggest one or two nodes which I can used in PHP? I am a little confused because all the examples are using simple XML files with tags like <author> and <title> e.t.c but my XML file has tags like following: <tr class="row_heading"> <tr class="row_odd"> <td align="left"> So tell me shall I use tag <tr> or <tr class="row_heading"> Quote Link to comment https://forums.phpfreaks.com/topic/125436-xml-parser-in-php/ Share on other sites More sharing options...
JonnoTheDev Posted September 23, 2008 Share Posted September 23, 2008 These are attributes for the node. When you are parsing the file do you need the attributes? If not most parsers should work OK as all they really do is convert the XML into a multi-dimensional array. Quote Link to comment https://forums.phpfreaks.com/topic/125436-xml-parser-in-php/#findComment-648504 Share on other sites More sharing options...
radalin Posted September 23, 2008 Share Posted September 23, 2008 You may use PEAR's XML_Unserializer library if you want. If you want to parse attributes of a node you just set an option to true and it's okay. $unser = new XML_Unserializer(array("parseAttributes" => true)); $status = $unser->unserialize($xmlString); if (PEAR::isError($stats)) { die("Xml Unserialize error"); } $resultArray = $unser->getUnserializedData(); You can also tell the parser to put the attributes into a predefined array by setting another option. And with getUnserializedData(), you get the mutli-dimensional associative array. Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/125436-xml-parser-in-php/#findComment-648612 Share on other sites More sharing options...
Mchl Posted September 23, 2008 Share Posted September 23, 2008 simplexml never let me down. Quote Link to comment https://forums.phpfreaks.com/topic/125436-xml-parser-in-php/#findComment-648633 Share on other sites More sharing options...
ali_kiyani Posted September 24, 2008 Author Share Posted September 24, 2008 Thanks for the replies guys. Let me try simplexml. In the mean time tell me is there some kind of recursive parser available? Because the document I am parsing has no fixed tags and they may increase or decrease. So I will be needing recursive parser if available the will go through all available nodes/tags. Quote Link to comment https://forums.phpfreaks.com/topic/125436-xml-parser-in-php/#findComment-649250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.