<?php
require_once("iecho.php");
$nvfile="http://blog.csdn.net/visioncat/Rss.aspx";
$nvfile="Rss.aspx";
$xml = new readXml($nvfile);
prt($xml->newsArray);
$r = ConvertArray( $xml->newsArray );
prt($r);
function ConvertArray( &$arr )
{
foreach ($arr as $ar) {
foreach ($ar as $key=>$value) {
$r[$key][]=$value;
}
}
return $r;
}
class readXML
{
var $currentElements = array();
var $newsArray = array();
var $itemCount;
var $xmlParser;
// Reads XML file into formatted html
function readXML($xmlFile)
{
$this->xmlParser = xml_parser_create();
xml_set_object( $this->xmlParser, $this );
xml_parser_set_option($this->xmlParser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($this->xmlParser, 'startElement', 'endElement');
xml_set_character_data_handler($this->xmlParser, 'characterData');
$data=file_get_contents ( $xmlFile );
xml_parse($this->xmlParser, $data, true);
xml_parser_free($this->xmlParser);
}
// Sets the current XML element, and pushes itself onto the element hierarchy
function startElement($parser, $name, $attrs)
{
array_push($this->currentElements, $name);
if($name == "item"){$this->itemCount += 1;}
}
// Prints XML data; finds highlights and links
function characterData($parser, $data)
{
$currentCount = count($this->currentElements);
$parentElement = $this->currentElements[$currentCount-2];
$thisElement = $this->currentElements[$currentCount-1];
if($parentElement == "item"){
if ($thisElement== "pubDate"){
$data= strtotime($data);
}
$this->newsArray[$this->itemCount-1][$thisElement] = $data;
}
else{
switch($name){
case "title":
break;
case "link":
break;
case "description":
break;
case "language":
break;
case "item":
break;}}
}
// If the XML element has ended, it is poped off the hierarchy
function endElement($parser, $name)
{
$currentCount = count($this->currentElements);
if($this->currentElements[$currentCount-1] == $name){
array_pop($this->currentElements);}
}
}
?>
require_once("iecho.php");
$nvfile="http://blog.csdn.net/visioncat/Rss.aspx";
$nvfile="Rss.aspx";
$xml = new readXml($nvfile);
prt($xml->newsArray);
$r = ConvertArray( $xml->newsArray );
prt($r);
function ConvertArray( &$arr )
{
foreach ($arr as $ar) {
foreach ($ar as $key=>$value) {
$r[$key][]=$value;
}
}
return $r;
}
class readXML
{
var $currentElements = array();
var $newsArray = array();
var $itemCount;
var $xmlParser;
// Reads XML file into formatted html
function readXML($xmlFile)
{
$this->xmlParser = xml_parser_create();
xml_set_object( $this->xmlParser, $this );
xml_parser_set_option($this->xmlParser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($this->xmlParser, 'startElement', 'endElement');
xml_set_character_data_handler($this->xmlParser, 'characterData');
$data=file_get_contents ( $xmlFile );
xml_parse($this->xmlParser, $data, true);
xml_parser_free($this->xmlParser);
}
// Sets the current XML element, and pushes itself onto the element hierarchy
function startElement($parser, $name, $attrs)
{
array_push($this->currentElements, $name);
if($name == "item"){$this->itemCount += 1;}
}
// Prints XML data; finds highlights and links
function characterData($parser, $data)
{
$currentCount = count($this->currentElements);
$parentElement = $this->currentElements[$currentCount-2];
$thisElement = $this->currentElements[$currentCount-1];
if($parentElement == "item"){
if ($thisElement== "pubDate"){
$data= strtotime($data);
}
$this->newsArray[$this->itemCount-1][$thisElement] = $data;
}
else{
switch($name){
case "title":
break;
case "link":
break;
case "description":
break;
case "language":
break;
case "item":
break;}}
}
// If the XML element has ended, it is poped off the hierarchy
function endElement($parser, $name)
{
$currentCount = count($this->currentElements);
if($this->currentElements[$currentCount-1] == $name){
array_pop($this->currentElements);}
}
}
?>