Displaying XML Data with PHP

I recently finished writing Sams Teach Yourself Programming with Java in 24 Hours, the fourth edition of an introductory book for Java programmers, which comes out in around two weeks.

I've been given wide editorial license with the book, so it contains unusual projects like Lottorobics, a lottery simulation applet that demonstrates why "Win the Lotto" is a terrible retirement plan.

The new edition adds chapters on XML and XML-RPC that use XOM and Apache XML-RPC, two great open source class libraries for Java. Programming projects in these chapters enable user lottery results to be tracked -- the applet sends the data to an XML-RPC server, which stores them in an XML file. In the years I've been offering the applet, users have won the lottery once in 4,877 simulated years of playing at a cost of $5.4 million dollars.

I wanted to display this lottery data on the web using PHP, so I've adapted some code for this purpose. The first release of the code, which I'm offering under the open source GNU Public License, shows how to read simple XML data with PHP.

If you do anything interesting with the code, and you don't mind releasing your work under the GPL, I'd like to add a few more sample programs to this project.

Comments

Rogers,

Wow, just spent an hour converting a static text list of files and file names from within the source of a web page to an XML file that's read in with your class. Now, of course, I have to maintain the XML file but... LOL. Cool code, thanks for this.

billsaysthis.com

Bill

Hi Rogers,
Great class! I used it to get XML data from amazon shop and to display it on my site.
Thanks,
Ivan

Funny how I find so many sites dating back so far. This is 2009, and it looks like you wrote this in 2005. I continue my search for a way to show someone's xml feed directly on my site without just telling them to subscribe to some silly feed (users just aren't as excited about feeds and techies are!).

Thanks for the info.

Add a Comment

All comments are moderated before publication. These HTML tags are permitted: <p>, <b>, <i>, <a>, and <blockquote>. This site is protected by reCAPTCHA (for which the Google Privacy Policy and Terms of Service apply).