JCE-Tech.com

PHP/MySQL Development

XML to Array Script

The XML to Array PHP script takes the hard work out of constantly developing custom PHP code to parse an XML document. A simple call the the XML to Array function with the appropriate repeating level will call your user defined function to process the XML data in a convenient, simple to use PHP array.

We've personally used this script to parse multiple XML and RSS feeds, and it has drastically decreased our development efforts. While there is no online demo, here is an example of what the script can do. The eBay RSS Store script utilizes the XML to Array script to parse the eBay RSS data feeds. For a demo of the eBay demo, click here.

Hint! Buy the eBay RSS script and and XML to Array script is included!

Sample XML (RSS) document

<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>CBC | Top Stories News</title>
<link>http://www.cbc.ca/news/</link>
<description>FOR PERSONAL USE ONLY</description>
<language>en-ca</language>
<lastBuildDate>Fri, 12 Jan 2007 16:28:57 EST</lastBuildDate>
<copyright>Copyright: (C) Canadian Broadcasting Corporation, http://www.cbc.ca/aboutcbc/discover/termsofuse.html#Rss</copyright>
<docs>http://www.cbc.ca/rss/</docs>
<image>
<title>CBC.ca</title>
<url>http://www.cbc.ca/rss/image/cbc_144.gif</url>
<link>http://www.cbc.ca</link>
</image>
<item>
<title>Pakistan objects to U.S. claims it shelters leaders of al-Qaeda</title>
<link>http://www.cbc.ca/world/story/2007/01/12/pakistan-alqaeda-070112.html?ref=rss</link>
<author>CBC</author>
<pubDate>Fri, 12 Jan 2007 12:30:21 EST</pubDate>
<description>Pakistani officials have sharply rejected U.S. claims that the country is harbouring senior al-Qaeda leaders and serving as a nerve centre controlling terror operations.</description>
</item>
<item>
<title>Extreme wind chill shuts down Manitoba schools</title>
<link>http://www.cbc.ca/canada/manitoba/story/2007/01/12/mba-cold.html?ref=rss</link>
<author>CBC</author>
<pubDate>Fri, 12 Jan 2007 11:14:31 EST</pubDate>
<description>Classes were cancelled at many schools Friday as most of southern Manitoba woke up under a deep freeze, with a wind chill making it feel like -48 C.</description>
</item>
<item>
<title>Ontario man accused of bilking investors of $8M</title>
<link>http://www.cbc.ca/money/story/2007/01/12/spencer.html?ref=rss</link>
<author>CBC</author>
<pubDate>Fri, 12 Jan 2007 15:32:06 EST</pubDate>
<description>Police in Toronto have issued a Canada-wide warrant for the arrest of a 25-year-old man who they say defrauded friends and relatives of $8 million.

</description>
</item>
<item>
<title>Beckham set to invade America</title>
<link>http://www.cbc.ca/sports/soccer/story/2007/01/12/david-beckham.html?ref=rss</link>
<author>CBC</author>
<pubDate>Fri, 12 Jan 2007 14:33:15 EST</pubDate>
<description>David Beckham is one of the most famous athletes in the world, but he's hardly a household name in the United States. He has five years to change that.</description>
</item>
<item>
<title>Water isn't only source of Montezuma's revenge</title>
<link>http://www.cbc.ca/consumer/story/2007/01/12/travellers-diarrhea.html?ref=rss</link>
<author>CBC</author>
<pubDate>Fri, 12 Jan 2007 15:29:28 EST</pubDate>
<description>Many Canadians, adhering only to the old travellers' maxim of 'don't drink the water,' are putting themselves at risk by ignoring other potential diarrhea triggers, a new study suggests.</description>
</item>
</channel>
</rss>


Code to process XML Document above

<?php

require_once('xml2array.php');

convert_xml('sample.xml', 'process_record', 'RSS/CHANNEL/ITEM');

function process_record($record)
{
echo "<p><a href=\"$record[LINK]\">$record[TITLE]</a></p>\n";
echo "<p>$record[DESCRIPTION]</p>\n";
}

?>


Output from above code

Pakistan objects to U.S. claims it shelters leaders of al-Qaeda

Pakistani officials have sharply rejected U.S. claims that the country is harbouring senior al-Qaeda leaders and serving as a nerve centre controlling terror operations.

Extreme wind chill shuts down Manitoba schools

Classes were cancelled at many schools Friday as most of southern Manitoba woke up under a deep freeze, with a wind chill making it feel like -48 C.

Ontario man accused of bilking investors of $8M

Police in Toronto have issued a Canada-wide warrant for the arrest of a 25-year-old man who they say defrauded friends and relatives of $8 million.

Beckham set to invade America

David Beckham is one of the most famous athletes in the world, but he's hardly a household name in the United States. He has five years to change that.

Water isn't only source of Montezuma's revenge

Many Canadians, adhering only to the old travellers' maxim of 'don't drink the water,' are putting themselves at risk by ignoring other potential diarrhea triggers, a new study suggests.

Usage

The script usage is quite simple. Simply include the script in any PHP code where you need to parse an XML document. Create a procedure that you want invoked with each repeating item in the XML document. Handle the array of XML data in your procedure as necessary. If you want to terminate the parsing before reaching the end of the XML document, simply return 1 (TRUE) in your procedure (e.g. return 1;).

The format of the call to xml2array is:

convert_xml(string $document, string $function, string $format);

document xml document name or location (e.g. document.xml or http:\\www.test.com\document.xml)
function the name of the procedure that will be invoked for each repeating item in the xml document
format the repeating tree structure (e.g. "RSS/CHANNEL/ITEM")

So, how much is this great script worth?

Special Price

Save $4.00
Not $5.
00

Only
$
1

You will soon be able to parse XML documents simply and quickly and you can start in just a few minutes from now!

But I am not just going to make a bunch of crazy claims, I will back up my promises with a 100%, 30 day money back guarantee.

I am going to do this because I am so confident that once you get your hands on the “XML to Array Script” I won’t be able to buy it back from you, let alone get you to simply give it up!

And that is exactly why you have my 100%, 30 day, no questions asked, iron clad money back guarantee:

GUARANTEE: Get the “XML to Array Script” right now and install it. Try the script out. If you are for any reason at all not 100% satisfied, send me an email within 30 days after purchasing, and I will personally refund every penny of your money, no questions asked. It's as simple as that.

 

Remember: this guarantee means that if for any reason you are not 100% satisfied with the “XML to Array Script”, all you have to do is send me an email and you will get a prompt, 100%, no questions asked refund.

You have absolutely NOTHING to lose! With the above guarantee the risk is 100% mine not yours. So why not give the “XML to Array Script” a try right now.



 
You will be downloading
The "XML to Array Script”
 within just a few minutes from now

 

License

You may not use, copy, rent, lease, sell, modify, decompile, disassemble, otherwise reverse engineer, or transfer the licensed program except as provided in this agreement. Any such unauthorized use shall result in immediate and automatic termination of this license.

Disclaimer

THE XML TO ARRAY SCRIPT IS "AS IS" AND WITHOUT ANY WARRANTY AS TO MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR ANY OTHER WARRANTIES EITHER EXPRESSED OR IMPLIED. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS, DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING OR MISUSING THIS SOFTWARE.