* Example Read data:
*
* $xml = new XML ("Dbase.xml", ' table ');
*
* $data = $xml->xml_fetch_array ();
*
* echo "
";
*
* Print_r ($DATA);
*
Class XML
{
var $dbase; database, the XML file to read
var $dbname; Database name, top-level element, consistent with database file name
var $dbtable; Data table, node to get
var $parser; Profiler
var $vals; Property
var $index; Index
var $dbtable _array;//node Array
var $array; An array of subordinate nodes
var $result; The 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 ("Unable to 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);
Iterate through the index, filtering out the node name to be evaluated: $dbtable
foreach ($this->index as $key = + $val) {
if ($key = = $this->dbtable) {
Get an array of nodes
$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 an array of arrays specified by the offset and length parameters.
Subordinate array of the nodes taken
$value =array_slice ($this->vals, $offset, $len);
Gets a valid array, merged into the result array
$this->array[]= $this->parseeff ($value);
}
return true;
}
Reads the XML file into and returns a stringhttp://www.bkjia.com/PHPjc/631415.html www.bkjia.com true http://www.bkjia.com/PHPjc/631415.html techarticle 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 ...