/*------------------------------------------------[the element selection engine]--*/
function init_selection_engine() {
$this->curr_tag=&$this->document['children']['?'][1];
}
function select($tname,$tindex) {
if ($tname==="") {
return true;
}
if ($name_count!=$index_count) {
$this->curr_tag=&$pre_sel;
return false;
}
for ($i=0;$i<$name_count;$i++) {
if (preg_match("/R\(.{1,}\)/i",$name_arr[$i])===1) {
$patern=substr($name_arr[$i],2,strlen($name_arr[$i])-3);
$count=0;
<?php
/*
* KXParse/2.3
* Initially started in March 2002 By Khalid Al-Kary
* Version 2.0 was started in 24 April 2003 by Khalid Al-Kary
* ----------------------------------------------------------
*/
class kxparse {
/*--[ tree mapper ]--*/
var $document;
var $xml;
var $xml_parser;
/*---[tag selection engine]--*/
var $curr_tag;
/*---[tree dumper]---*/
var $dump_pos;
var $dump_temp;
/*----[io handling]--*/
var $file;
/*--------------------------------------------------[the constructor]-----*/
function kxparse($file=false) {
$this->file=$file;
if ($file!=false) {
$flag=$this->init_mapper();
if (!$flag) {
return false;
}
$this->init_tree_dumper();
$this->init_selection_engine();
}
}
/*------------------------------------------[IO handling functions]---------*/
function load($file=false) {
if ($file===false) {
$flag=$this->init_mapper();
return $flag;
}
else {
$this->file=$file;
$flag=$this->init_mapper();
if ($flag) {
$this->init_tree_dumper();
$this->init_selection_engine();
}
return $flag;
}
}
function save($file=false) {
if ($file==false) {
$file=$this->file;
}
if (!$file) {
return false;
}
$this->dump_tree();
$flag=$this->io_put_content($file, $this->dump_temp);
$this->dump_temp="";
if ($flag==false) {
return false;
}
return true;
}
function load_string($str) {
$this->xml=$str;
$this->file=false;
$flag=$this->init_mapper();
$this->init_tree_dumper();
$this->init_selection_engine();
return $flag;
}
function io_put_content($filename, $content) {
$flag=true;
$fd=fopen($filename, "wb");
if ($fd==false) {
$flag=false;
}
else {
$flag=fwrite($fd, $content);
}
fclose($fd);
return $flag;
}
function io_get_content($filename) {
$fd=fopen($filename,"r");
$content="";
if ($fd==false) {
$content=false;
}
else {
while (!feof($fd)) {
$content.=fread($fd,4096);
}
}
fclose($fd);
return $content;
}
function io_gen_filename($prefix) {
$i=0;
$filename="";
while (true) {
if (!file_exists(($i==0) ? $prefix : $prefix.".".$i)) {
$filename=($i==0) ? $prefix : $prefix.".".$i;
break;
}
$i++;
}
return $filename;
}
function get_content($reswap=true) {
$this->dump_tree();
$val=$this->dump_temp;
$this->dump_temp="";
return $val;
}
function get_file_name() {
return $this->file;
}