PHP class for operating XML to create a database_PHP tutorial

WBOY
Release: 2016-07-13 16:58:25
Original
803 people have browsed it


* example read data:
*
* $xml = new xml("dbase.xml",'table');
*
* $data=$xml->xml_fetch_array();
*
* echo "

";
*
* print_r($data);
*

class xml
{
var $dbase; //Database, XML file to be read
var $dbname; //Database name, top-level element, consistent with database file name
var $dbtable; //Data table, node to be obtained
var $parser; //Parser
var $vals; //Attribute
var $index; //index
var $dbtable_array;//Node array
var $array; //Array of subordinate nodes
var $result; //returned result
var $querys;

function xml($dbase,$dbtable)
{
$this->dbase=$dbase;
$this->dbname=substr($dbase,strrpos($dbase,"/") 1,-4);
$this->dbtable=$dbtable;
$data=$this->ReadXml($this->dbase);
if(!$data){
die("Cannot read $this->dbname.xml");
}
$this->parser = xml_parser_create();
xml_parser_set_option($this->parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($this->parser,XML_OPTION_SKIP_WHITE,1);
xml_parse_into_struct($this->parser,$data,$this->vals,$this->index);
xml_parser_free($this->parser);
//Traverse the index and filter out the nodes to be valued. Node name: $dbtable
foreach ($this->index as $key=>$val) {
if ($key == $this->dbtable) {
//Get node array
$this->dbtable_array = $val;
} else {
continue;
}
}
for ($i=0; $i < count($this->dbtable_array); $i =2) {
$offset = $this->dbtable_array[$i] 1;
$len = $this->dbtable_array[$i 1] - $offset;
//array_slice() returns a sequence in the array array specified by the offset and length parameters.
//The lower level array of the taken node
$value=array_slice($this->vals,$offset,$len);
//Get valid arrays and merge them into the result array
$this->array[]=$this->parseEFF($value);
}
return true;
}
//Read the XML file and return the string

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631415.htmlTechArticle?php * example Read data: * * $xml = new xml(dbase.xml,'table') ; * * $data=$xml-xml_fetch_array(); * * echo pre style=font-size:12px;; * * print_r($data); * class xml { var $d...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template