Question handling xml data


Posted on 16th Feb 2014 07:03 pm by admin

Hello,

I have sucessfull followed this tutorial
http://www.phpfreaks.com/tutorial/handling-xml-data
Did you know?Explore Trending and Topic pages for more stories like this.

and used xpath to find the books I need, here is my code

Code: [Select]<?php
// load SimpleXML
$books = new SimpleXMLElement('books.xml', null, true);

echo <<<EOF
<table>
<tr>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Price at Amazon.com</th>
<th>ISBN</th>
</tr>

EOF;
foreach($books->xpath('book1/book') as $book) // loop through our books
{
echo <<<EOF
<tr>
<td>{$book->title}</td>
<td>{$book->author}</td>
<td>{$book->publisher}</td>
<td>${$book->amazon_price}</td>
<td>{$book['isbn']}</td>
</tr>

EOF;
}
echo '</table>';
?>

now I want to only show the first 5 books in the xml file as it is updated regularly

I can't seem to figure out how to do this.

any help would be great , thanks
No comments posted yet

Your Answer:

Login to answer
321 Like 33 Dislike
Previous forums Next forums
Other forums

Sessions work for me and not others?
I'm having a bit of bad luck with sessions. In the past they have worked fine for me, but this time

Email Form Syntax Issue
I need the TO: in email to display To: CEO instead of To: abc@mail.com

How to alter the scri

Unable to display contents in Second Drop Down Box
Hi All,

What I am trying to do is 2 dependent drop down boxes and when user selects su

How to Detect it is public_html or httpdocs?
How to check whether it is cPanel or Plesk?

If it found public_html perform <?php incl

Auto install
Hi I have a directory lets say "apps" that I then have more folders ie "email",

php/mysql auto logout after 2 hour and reset password
Hi all,

This I hope will make sense. I've the following code which when a user logins in, cr

PHP Session Issue
I'm having an issue with one section on my website dealing with sessions. Now I know that myself and

PHP5 - AJAX help
I've been following the tutorial on w2schools (http://www.w3schools.com/php/php_ajax_database.asp) a

PHP Login
Hey!
I got this shopcart code online, am trying to modify it but am getting an error when i try a

Need Successful Return
Hello I am currently working a form here, and I have everything figured out except when I click the

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash