bravo14 Posted May 29, 2012 Share Posted May 29, 2012 Hi Guys I have an XML feed that produces the following data:- <?xml version="1.0" encoding="utf-8" standalone="yes" ?> - <bookCategories> - <category> <id>addressbooks</id> <name>Address Books & Journals</name> </category> - <category> <id>art</id> <name>Art, Architecture & Photography</name> </category> - <category> <id>audiocd</id> <name>Audio Books</name> </category> - <category> <id>audiocassette</id> <name>Audio Cassettes</name> </category> - <category> <id>bestsellers</id> <name>Best Sellers</name> </category> I want to list each of the category names I am using the code below: <?php //category listing $file="http://book.find-services.co.uk/bookCategories.aspx?site=Purelybooks"; $dom=new DOMdocument(); $dom->load($file); $xml=simplexml_import_dom($dom); echo $xml->category; ?> The categories are not showing at all, there are no errors being produced. Hopefully someone can give me some pointers in the right direction. Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/ Share on other sites More sharing options...
PravinS Posted May 29, 2012 Share Posted May 29, 2012 Try this <?php $file = "http://book.find-services.co.uk/bookCategories.aspx?site=Purelybooks"; $xml = simplexml_load_file($file); var_dump($xml); ?> Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/#findComment-1349440 Share on other sites More sharing options...
bravo14 Posted May 29, 2012 Author Share Posted May 29, 2012 That shows the XML feed so at least I know it is getting the data, ultimately, what I want to do is compile a list with links in the following layout <li><"a href=category.php?xml id">xml category</a></li> Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/#findComment-1349442 Share on other sites More sharing options...
PravinS Posted May 29, 2012 Share Posted May 29, 2012 Yes, you can now use XML parser or download some XML parsing class Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/#findComment-1349444 Share on other sites More sharing options...
Barand Posted May 29, 2012 Share Posted May 29, 2012 <?php $xml = simplexml_load_file('bookCats.xml'); foreach($xml->xpath('//name') as $cat) { echo $cat . '<br />'; } ?> Results : Address Books & Journals Art, Architecture & Photography Audio Books Audio Cassettes Best Sellers Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/#findComment-1349445 Share on other sites More sharing options...
Barand Posted May 29, 2012 Share Posted May 29, 2012 just spotted your revised requirement for links <?php $xml = simplexml_load_file('bookCats.xml'); echo "<ul>\n"; foreach($xml->xpath('//category') as $cat) { echo "<li><a href='category.php?id=$cat->id'>$cat->name</a></li>\n"; } echo "</ul>\n"; ?> results <ul> <li><a href='category.php?id=addressbooks'>Address Books & Journals</a></li> <li><a href='category.php?id=art'>Art, Architecture & Photography</a></li> <li><a href='category.php?id=audiocd'>Audio Books</a></li> <li><a href='category.php?id=audiocassette'>Audio Cassettes</a></li> <li><a href='category.php?id=bestsellers'>Best Sellers</a></li> </ul> Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/#findComment-1349447 Share on other sites More sharing options...
bravo14 Posted May 30, 2012 Author Share Posted May 30, 2012 That works perfectly, however using the same layout to generate another dataset I am getting the following error Parse error: syntax error, unexpected T_VARIABLE in /home/sites/purelybooks.com/public_html/includes/best_sellers_inc.php on line 10 The code is <?php //category listing $best_sellers_file = "http://book.find-services.co.uk/bookSearch.aspx?site=purelybooks&category=newreleases&sort=popular&pagesize=10"; echo ('<div class="jcarousel-skin-name"> <div class="jcarousel-container"> <div class="jcarousel-clip"> <ul class="jcarousel-list">'); $best_sellers_xml = simplexml_load_file($best_sellers_file); foreach($best_sellers_xml->xpath('//book') as $best_sellers_book) { var_dump $best_sellers_book; echo ('<li class="jcarousel-item">'$best_sellers_book->title'</li>\n'); } echo('</ul> </div> </div> </div>'); ?> The xml file I am reading looks like <?xml version="1.0" encoding="UTF-8" standalone="true"?> -<books>-<book><id>0007466072</id><isbn13>9780007466078</isbn13><asin>0007466072</asin><title>A Song of Ice and Fire (5) - A Dance With Dragons: Part 2 After the Feast</title><numberOfPages>592</numberOfPages>-<authors><author>George R. R. Martin</author></authors><published>15 March 2012</published><review/><rrp>8.99</rrp><publisher>Harper Voyager</publisher><cover>Paperback</cover><imageURL>http://images-eu.amazon.com/images/P/0007466072.02.MZZZZZZZ.jpg</imageURL><thumbnailURL>http://images-eu.amazon.com/images/P/0007466072.02.THUMBZZZ.jpg</thumbnailURL><pricesLastCached>30/05/2012 05:06:10</pricesLastCached><minimumPrice>3.86</minimumPrice></book>-<book><id>0007466064</id><isbn13>9780007466061</isbn13><asin>0007466064</asin><title>A Song of Ice and Fire (5) - A Dance With Dragons: Part 1 Dreams and Dust</title><numberOfPages>704</numberOfPages>-<authors><author>George R. R. Martin</author></authors><published>15 March 2012</published><review/><rrp>8.99</rrp><publisher>Harper Voyager</publisher><cover>Paperback</cover><imageURL>http://images-eu.amazon.com/images/P/0007466064.02.MZZZZZZZ.jpg</imageURL><thumbnailURL>http://images-eu.amazon.com/images/P/0007466064.02.THUMBZZZ.jpg</thumbnailURL><pricesLastCached>29/05/2012 18:00:50</pricesLastCached><minimumPrice>3.86</minimumPrice></book> Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/#findComment-1349726 Share on other sites More sharing options...
Barand Posted May 30, 2012 Share Posted May 30, 2012 echo ('<li class="jcarousel-item">'$best_sellers_book->title'</li>\n'); no concatenation operators Link to comment https://forums.phpfreaks.com/topic/263311-simple-xml-help/#findComment-1349727 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.