I am going to give you the code required to parse XML easily
usingone file.Just copy and paste the code and customize it
accordinglyAny doubts feel free to contact me.
The first file is the XML file
parse.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<rss version=”2.0″>
<channel>
<title>Tutorialz Images</title>
<link>http://www.tutorialz.tk</link>
<language>en-us</language>
<image>
<url>102724_31082007.jpg</url>
<title></title>
<link>http://www.tutorialz.tk</link>
<description/>
</image>
<image>
<url>369877_31082007.jpg</url>
<title></title>
<link>http://www.tutorialz.tk/22562/userid/3</link>
<description/>
</image>
<image>
<url>898438_0312080814461mira5abcjpg.jpg</url>
<title> </title>
<link>http://www.tutorialz.tk/22560/userid/3</link>
<description/>
</image>
<image>
<url>211000_withkids.jpg</url>
<title>rahul and gokul
</title>
<link>http://www.tutorialz.tk/22469/userid/3</link>
<description/>
</image>
<image>
<url>180625_cycle.jpg</url>
<title>
</title>
<link>http://www.tutorialz.tk/22467/userid/3</link>
<description/>
</image>
<image>
<url>368384_mission.jpg</url>
<title>The mission begins…
</title>
<link>http://www.tutorialz.tk/22465/userid/3</link>
<description/>
</image>
<image>
<url>370625_04082007.jpg</url>
<title>
</title>
<link>http://www.tutorialz.tk/22350/userid/3</link>
<description/>
</image>
<image>
<url>292629_06082007744.jpg</url>
<title>
</title>
<link>http://www.tutorialz.tk/22330/userid/3</link>
<description/>
</image>
<image>
<url>22314</url>
<title></title>
<link>http://www.tutorialz.tk/22314/userid/3</link>
<description/>
</image>
<image>
<url>22313</url>
<title>comfort inn attham</title>
<link>http://www.tutorialz.tk/22313/userid/3</link>
<description/>
</image>
<image>
<url>22295</url>
<title>dial 100 if you see any of these person</title>
<link>http://www.tutorialz.tk/22295/userid/3</link>
<description/>
</image>
<image>
<url>811298_30072007676.jpg</url>
<title>
</title>
<link>http://www.tutorialz.tk/22200/userid/3</link>
<description/>
</image>
<image>
<url>974623_dog.jpg</url>
<title>
</title>
<link>http://www.tutorialz.tk/22179/userid/3</link>
<description/>
</image>
<image>
<url>270873_15082007.jpg</url>
<title></title>
<link>http://www.tutorialz.tk/22103/userid/3</link>
<description/>
</image>
<image>
<url>22102</url>
<title></title>
<link>http://www.tutorialz.tk/22102/userid/3</link>
<description/>
</image>
<image>
<url>22101</url>
<title>kenney</title>
<link>http://www.tutorialz.tk/22101/userid/3</link>
<description/>
</image>
<image>
<url>22100</url>
<title></title>
<link>http://www.tutorialz.tk/22100/userid/3</link>
<description/>
</image>
<image>
<url>22099</url>
<title></title>
<link>http://www.tutorialz.tk/22099/userid/3</link>
<description/>
</image>
<image>
<url>22098</url>
<title></title>
<link>http://www.tutorialz.tk/22098/userid/3</link>
<description/>
</image>
<image>
<url>22097</url>
<title></title>
<link>http://www.tutorialz.tk/22097/userid/3</link>
<description/>
</image>
</channel>
</rss>
the second one is the PHP fileparse.php<?phpclass RSSParser{
var $url;
# (string) – URL of feed
var $page;
# (string) – Raw file contents of RSS Feed
var $xml;
# (object) – Object data of RSS Feed
var $channel;
# (object) – Channel Object containing feed information and images
var $images;
# (array) – RSS images
var $feed;
# (array) – Feed Information ( title, desc, publish date )
/*
Class Constrictor
Arguements:
url: Feed URL, can be a local file, or online ( http:// )
- url is required in order to execute the constrictor
*/
function __construct ( $url )
{
/*
Do we have PHP5 Installed?
If we do not have it installed,
Kill the script immediately.
*/
if ( intval( phpversion() ) < 5 )
{
die ( ‘PHP5 is required to execute this class.’ );
}
/*
Does the extention class exist?
Since it is an internal class
Compiled into PHP5, we can check
Whether it is installed or not.
*/
else if ( !class_exists ( ‘SimpleXMLElement’ ) )
{
die ( ‘Please re-compile PHP5 with the simpleXmlElement extention.’ );
}
// Set the URL of the feed internally.
$this->setRSS ( $url );
// Get the page contents of that feed.
$this->getRSS ();
// Parse RSS information
$this->parseRSS ();
}
/*
Function: setRSS
Arguements:
url – RSS Feed url which is set interally
- url is required to run this function
*/
function setRSS ( $url )
{
$this->url = $url;
}
/*
Function getRSS
- Get the feed source of the rss feed
*/
function getRSS ()
{
$this->feed = file_get_contents ( $this->url )
or die ( ‘RSS feed was not found’ );
}
/*
Function: parseRSS
- Parses the rss source
- Places feed images in array: $this->images
- Places feed details in array: $this->feed
*/
function parseRSS ()
{
// Since the extention is loaded, lets create a new
// instance of this class.
$this->xml = new SimpleXMLElement ( $this->feed );
// The XML Object has another child called channel.
// It holds the RSS details as well as images
$this->channel = $this->xml->channel;
// Lets set the feed details
// – Information about the RSS Feed
$this->feed = array
(
‘title’ => $this->clean ( $this->channel->title ),
‘description’ => $this->clean ( $this->channel->description ),
‘link’ => $this->clean ( $this->channel->link ),
‘date’ => $this->clean ( $this->channel->pubDate ),
‘image’ => ( $this->channel->image->url ) ? $this->clean ( $this->channel->image->url ) : false,
);
// Checks if we have any images present.
// Yes, it is possible that a feed is empty =/
if ( is_object ( $this->channel->image ) && count( $this->channel->image ) )
{
// Lets loop through all the <image> objects
foreach ( $this->channel->image as $image )
{
// Add an image to the array
//$i=1;
$this->images[] = array
(
‘title’ => $this->clean ( $image->title ),
‘link’ => $this->clean ( $image->link ),
‘description’ => $this->clean ( $image->description ),
‘category’ => $this->clean ( $image->category ),
‘url’ => $this->clean ( $image->url),
);
}
}
}
/*
Function clean
Argueuemts:
i – string in which to clean.
Cleans off the object tag from an object variable.
*/
function clean ( $i )
{
return (string) htmlspecialchars ( html_entity_decode ( $i ) );
}
}
$RSSParser = new RSSParser ( ‘parse.xml’ );
echo ‘Thank You,You are successful in parsing XML.<br><b>The parsed XML is:-</b> <pre>’;
print_r( $RSSParser->feed );
print_r( $RSSParser->images );
?>
I have tested this and the script is working fine….If u are expericed OOP programmer you can easily customize the script.Thax
Incoming search terms:
- Next Image SlideShow: Comment added on: Your Comment (14)
- yii dropdownlist ajax (7)
- Next Image SlideShow: Comment added on: Your Comment|Next Image SlideShow: Comment added on: Your Comment|DatsoGallery By Andrey Datso|inurl:option=com_datsogallery (6)
- inurl:change php?js= (6)
- datsogallery by andrey datso comment added on exhibition (4)
- message from webpage url is required (3)
- images scroller in jquery (3)
- jquery marquee continuous (3)
- message from web page change title (3)
- visitor tracker in php (2)
- using rounded corners in image with jquery in fadein fadeout script (2)
- php search results pagination (2)
- image gallery with pagination in php (2)
- next image slideshow comment added on your comments meddle (2)
- examples upload file yii (2)
- zoom jquery blob image (2)
- cooking inurl:/guestbook html (2)
- imagecreate blob (2)
- fpdf watermark (2)
- rss feed parser images with xml (2)
- tumblr scrolling title code (2)
- background fixed image change on every 5sec using jquery (2)
- alert title javascript message from webpage (2)
- background image change on every 5sec tutorials using jquery (2)
- jquery image marquee continuous (2)
- ajax textbox loading search in php (2)
- php delete image tutorial (2)
- php mysql image slider (2)
- php mpdf watermark (2)
- jcarousellite iscroll (2)
- parse images in url line (1)
- panda3d load image (1)
- parsing made easy (1)
- next prev button in java mysql (1)
- message from webpage hide javascript (1)
- paging fadeout jquery (1)
- mysql search results in image slider (1)
- mysql to change the color of the image on clicking (1)
- new year countdown jquery (1)
- Sample url images xml parsing (1)
You will also be interested in ,
- Adding apache handlers in cpanel
- Display Tags in wordpress
- How to avoid direct access to a file in php
- Copy mysql column in varchar to type date
- Get Method and Array Manipulation In Symfony
- Find the string and then the line number using php from text file
- Date in title bar using php
- How To Set And Get Cookies Using PHP
- Ajax Page With PHP
- Pass PHP Value To Javascript

