petschephp Posted September 23, 2011 Share Posted September 23, 2011 I am trying to parse a XML file using SimpleXML, but I can't figure out how to display <Category> name and each <feature> Here's a example of the XML file. <Vehicle> <Description>To set an appointment callor email </Description> <Features> <Category Name="Comfort"> <Feature>Front Air Conditioning</Feature> <Feature>Front Air Conditioning Zones: Single</Feature> <Feature>Front Air Conditioning: Climate Control</Feature> </Category> </Features> </Vehicle> Link to comment https://forums.phpfreaks.com/topic/247737-help-with-xml-parser/ Share on other sites More sharing options...
Maq Posted September 23, 2011 Share Posted September 23, 2011 What exactly is the problem? Do you have any code? Example #4 shows you how to loop through: http://us3.php.net/manual/en/simplexml.examples-basic.php For the name you need the attribute: http://us3.php.net/manual/en/simplexmlelement.attributes.php Link to comment https://forums.phpfreaks.com/topic/247737-help-with-xml-parser/#findComment-1272146 Share on other sites More sharing options...
petschephp Posted September 23, 2011 Author Share Posted September 23, 2011 Here is the code. It works, but I just can't figure out how to get the features to display. // load SimpleXML $cars = new SimpleXMLElement('inventory.xml', null, true); echo <<<EOF <table> <tr> <th>ID</th> <th>Stock Number</th> <th>InventoryDate</th> <th>CreatedDate</th> <th>VIN</th> <th>TYPE</th> <td>Features</td> </tr> EOF; foreach($cars as $car) // loop through our cars { echo <<<EOF <tr> <td>{$car->ID}</td> <td>{$car->StockNum}</td> <td>{$car->InventoryDate}</td> <td>{$car->CreatedDate}</td> <td>{$car->VIN}</td> <td>{$car->TYPE}</td> <td></td> </tr> EOF; } echo '</table>'; Link to comment https://forums.phpfreaks.com/topic/247737-help-with-xml-parser/#findComment-1272152 Share on other sites More sharing options...
petschephp Posted September 24, 2011 Author Share Posted September 24, 2011 Can anyone help? Link to comment https://forums.phpfreaks.com/topic/247737-help-with-xml-parser/#findComment-1272429 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.