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

Data storage spaces in varchar2
Trying to understand what's happening.
I am selecting a value from a table that is defined as c

Filtering for a phrase using pregmatch
Here is my code which looks for addresses which start with ' src=" '

Code: [Select]preg_

Creating XML with php
I need to creat an XML with php and have successfully produced a valid output.
The problem I hav

parse error
On my local machine I keep getting parse error for my footer. When I put it online, it doesn't show

CURL question
i am wondering if it's possible to use multi curl with login something like

login once to web

Revoking alter any table from a schema
Hi All,

i am working in Oracle 10g.
my requirement is to revoke all kind of DDL oper

Quick variable question
hey guys/gals,
im trying to write a php script and it works fine as i have it, but i need to set

Weird problem with SELECT command..Help!
Hi!

It seems I'm having a really weird problem with SQL SELECT command....I have table into a

Undefined index: username HELP NEWBIE
I am trying a simple login/logout for my website. It works well with checking if the username exists

Transaction variant for VA02 not working
My requirement is to have transaction for user to only add the output and print a sales order.

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