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

Find occurences of unicode characters in string
I need to prohibit filenames with everything but English characters and numbers but regexp and strin

Help on Order Entry Form/System Where is best to begin.
I have a dilema and a very short amount of time at this point and I'm looking for some help on decid

double and single quotes in text fields acting up... help please
Single quotes, when entered into a text field, create an sql error upon Submit. It seems to create t

selection tool on raster image
Hi!
I have to implement in my app a selection tool which lets users to select region of any shape

generating random codes
Hi guys n gals,

I have a requirement to generate 250,000 unique codes...

These codes a

Not loading image
When this function gets loaded it doesn't load the image just trying to figure out why.

Code:

Email "$"
Hello!!

Any PHP guy with a bit of a knowledge in Flash ?

When I send a JPEG from flash

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

update post issues
I am trying to create an update to a post function, while the update does occur, the page routing an

Access database inside of a validation class
Hello,

For quite some time, I have been using functions to validate form input and access 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