XML-Simple: Read Simple XML Data with PHP

XML-Simple is a PHP class library that parses XML data. A script is included that demonstrates how to use the library to load the data into an array and display it on a web page.

Version 1.01.

Links:

This software was developed by Rogers Cadenhead, publisher of the Workbench weblog, based on original code by Jim Winstead Jr.. It has been released under the GNU General Public License.

  • PHP

I'm running the software on PHP 4.3.2. I think it should work with PHP 4 or higher, but that's only a guess.

Installation instructions
  • Download the XML-Simple archive in either tar.gz or zip format and unpack the archive.

  • Save the PHP class library xml-simple.php in a directory where it will be accessible to PHP web pages. I put it in the software's include_path directory, which is often /usr/local/lib/php on new installations.
Documentation

An example use of this class is demonstrated by the lottorobics.php script, which you can see running on the Lottorobics page.

Xml-Simple employs the following variables:

  • $tree, an array that holds parsed XML data as either name-value pairs (for character data) or arrays (for subelements)

  • $error: a descriptive error message, if the class fails to execute successfully

The following constructor and methods are available:

  • xml_simple($encoding = "UTF-8"): Create the XML parser that will read XML data formatted with the specified encoding (default "UTF-8")

  • parse($data): Parse XML data, storing it in the instance variable . Returns false if the data cannot be parsed.
Version History

  • Version 1.01: Updated license to reflect Jim Winstead's permission to release all of it under the GPL, Oct. 12, 2005
  • Version 1.0: Original release, Sept. 21, 2005
License

Copyright 2005 Rogers Cadenhead

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.