3
2023-06-13 09:13:43 时间
{
if(is_array($value)&&!$delete)
{
foreach($valueas$suboption=>$subvalue)
{
$this->{$option}["$suboption"]=$subvalue;
}
}
else
{
$this->$option=$value;
}
}
}
}
}
//thesearethefunctions,whichareintendedtobeoverrideninuserclasses
/**
*
*@param mixed
*@return object DomNode
*@access private
*/
functioninsertNewResult(&$metadata)
{
if($this->xmlroot)
return$this->xmlroot->new_child($this->tagNameResult,NULL);
else
{
$this->xmlroot=$this->xmldoc->add_root($this->tagNameResult);
//PHP4.0.6had$root->nameastagname,checkforthathere...
if(!isset($this->xmlroot->{$this->tagname}))
{
$this->tagname="name";
}
return$this->xmlroot;
}
}
/**
* tobewritten
*
*@param objectDomNode$parent_row
*@param mixed$res
*@param mixed$key
*@param mixed&metadata
*@return objectDomNode
*@accessprivate
*/
functioninsertNewRow($parent_row,$res,$key,&$metadata)
{
return $parent_row->new_child($this->tagNameRow,Null);
}
/**
* tobewritten
*
*@param objectDomNode$parent
*@param mixed$res
*@param mixed$key
*@param mixed&$metadata
*@param mixed&$subrow
*@return objectDomNode
*@accessprivate
*/
functioninsertNewElement($parent,$res,$key,&$metadata,&$subrow)
{
return $parent->new_child($metadata[$key]["name"],$this->xml_encode(trim$res[$key]));
}
/**
* tobewritten
*
*@param mixed$key
*@param mixed$value
*@param mixed&$metadata
*@accessprivate
*/
functionaddTableInfo($key,$value,&$metadata){
}
//endfunctions,whichareintendedtobeoverrideninuserclasses
//herecomesomehelperfunctions...
/**
*makeutf8outoftheinputdataandescape&with&and"<"with"<"
*(weassumethatwhenthere"snospaceafter<it"satag,whichweneedinthexml)
* I"mnotsure,ifthisisthestandardway,butitworksforme.
*
*@param stringtexttobeutfed.
*@accessprivate
*/
functionxml_encode($text)
{
if(function_exists("iconv")&&isset($this->encoding_from)&&isset($this->encoding_to))
{
ini_set("track_errors",1);
$text=iconv($this->encoding_from,$this->encoding_to,ereg_replace("&","&",ereg_replace("<","<",$text)));
if(!isset($text))
{
if(isset($php_errormsg))
{
$errormsg="error:$php_errormsg";
}
else
{
$errormsg="undefinediconverror,turnontrack_errorsinphp.initogetmoredetails";
}
returnPEAR::raiseError($errormsg,Null,PEAR_ERROR_DIE);
}
else{
return$text;
}
}
else
{
//$text=utf8_encode(ereg_replace("&","&",ereg_replace("<","<",$text)));
$text=trim(ereg_replace("&","&",ereg_replace("<","<",$text)));
// echo$text;
}
return$text;
}
//takenfromkc@hireability.comathttp://www.php.net/manual/en/function.array-merge-recursive.php
/**
*Thereseemedtobenobuiltinfunctionthatwouldmergetwoarraysrecursivelyandclobber
* anyexistingkey/valuepairs.Array_Merge()isnotrecursive,andarray_merge_recursive
* seemedtogiveunsatisfactoryresults...itwouldappendduplicatekey/values.
*
* Sohere"sacrossbetweenarray_mergeandarray_merge_recursive
**/
/**
*
*@param arrayfirstarraytobemerged
*@param arraysecondarraytobemerged
*@return arraymergedarray
*@accessprivate
*/
functionarray_merge_clobber($a1,$a2)
{
if(!is_array($a1)
!is_array($a2))returnfalse;
$newarray=$a1;
while(list($key,$val)=each($a2))
{
if(is_array($val)&&is_array($newarray[$key]))
{
$newarray[$key]=$this->array_merge_clobber($newarray[$key],$val);
}
else
{
$newarray[$key]=$val;
}
}
return$newarray;
}
/**
*Addsaxmlstringto$this->xmldoc.
*It"sinsertedonthesamelevelasa"normal"resultset,meansjustasachildrenof<root>
*ifaxpathexpressionissupplied,ittakesthatforselectingonlypartofthexml-file
*
*thecleancodeworksonlywithphp4.0.7
*forphp4.0.6:
*Ifoundnocleanermethodthanthebelowone.it"smaybenasty(xmlObject->string->xmlObject),
* butitworks.IfsomeoneknowshowtoaddwholeDomNodestoanotherone,letmeknow...
*
*@param stringxmlstring
*@param mixedxpath eitherastringwiththexpathexpressionoranarraywith"xpath"=>xpathexpression and"root"=tag/subtag/etc,whicharethetagstobeinsertedbeforetheresult
*@accessprivate
*/
functiondoXmlString2Xml($string,$xpath=Null)
{
//checkifwehavearecentdomxml.otherwiseusetheworkaround...
$version=explode(".",phpversion());
if(!($version[0]<=4and$version[1]<=0and$version[2]<7)){
if(is_array($xpath))
{
if(isset($xpath["root"]))
{
$root=$xpath["root"];
}
$xpath=$xpath["xpath"];
}
$tmpxml=xmldoc($string);
$subroot=$this->xmlroot;
if(isset($root))
{
$roots=explode("/",$root);
foreach($rootsas$rootelement)
{
if(strlen($rootelement)>0)
{
$subroot=$subroot->new_child($rootelement,"");
}
}
}
//$this->xmlroot->addchilddoessomestrangethingswhenaddednodesfromxpath....sothiscommenthelpsout
$newchild=$subroot->add_child($this->xmldoc->create_comment("thepurposeofthiscommentisaworkaroundinsql2php.phpline".__LINE__));
//ifnoxpathisgiven,justtakethewholefile
if((is_null($xpath)))
{
$newchild->append_child($tmpxml->root());
}
else
{
$xctx=$tmpxml->xpath_new_context();
$xnode=xpath_eval($xctx,$xpath);
foreach($xnode->nodesetas$node)
{
$newchild->append_child($node);
}
}
}
else{
$MainXmlString=$this->xmldoc->dumpmem();
$string=preg_replace("/<\?xml.*\?>/","",$string);
$MainXmlString=preg_replace("/<".$this->xmlroot->{$this->tagname}."\/>/","<".$this->xmlroot->{$this->tagname}."></".$this->xmlroot->{$this->tagname}.">",$MainXmlString);
$MainXmlString=preg_replace("/<\/".$this->xmlroot->{$this->tagname}.">/",$string."</".$this->xmlroot->{$this->tagname}.">",$MainXmlString);
$this->xmldoc=xmldoc($MainXmlString);
$this->xmlroot=$this->xmldoc->root();
}
}
/**
*setstheencodingforthedb2xmltransformation
*@param string$encoding_fromencodingtotransformfrom
*@param string$encoding_toencodingtotransformto
*@accesspublic
*/
functionsetEncoding($encoding_from="ISO-8859-1",$encoding_to="UTF-8")
{
$this->encoding_from=$encoding_from;
$this->encoding_to=$encoding_to;
}
/**
*@paramarray$parentTablesparenttochildrelation
*@accesspublic
*/
functionSetParentTables($parentTables)
{
foreach($parentTablesas$table=>$parent)
{
$table_info["parent_table"][$table]=$parent;
}
$this->SetOptions(array("user_tableInfo"=>$table_info));
}
/**
*returnsthecontentofthefirstmatchofthexpathexpression
*
*@param string$exprxpathexpression
*@return mixedcontentoftheevaluatedxpathexpression
*@access public
*/
functiongetXpathValue($expr)
{
$xpth=$this->xmldoc->xpath_new_context();
$xnode=xpath_eval($xpth,$expr);
if(isset($xnode->nodeset[0]))
{
$firstnode=$xnode->nodeset[0];
$children=$firstnode->children();
$value=$children[0]->content;
return$value;
}
else
{
returnNull;
}
}
/**
*getthevaluesasanarrayfromthechildtagsfromthefirstmatchofthexpathexpression
*
*@param stringxpathexpression
*@return arraywithkey->valueofsubtags
*@access public
*/
functiongetXpathChildValues($expr)
{
$xpth=$this->xmldoc->xpath_new_context();
$xnode=xpath_eval($xpth,$expr);
if(isset($xnode->nodeset[0]))
{
foreach($xnode->nodeset[0]->children()as$child)
{
$children=$child->children();
$value[$child->{$this->tagname}]=$children[0]->content;
}
return$value;
}
else
{
returnNull;
}
}
}
?>
if(is_array($value)&&!$delete)
{
foreach($valueas$suboption=>$subvalue)
{
$this->{$option}["$suboption"]=$subvalue;
}
}
else
{
$this->$option=$value;
}
}
}
}
}
//thesearethefunctions,whichareintendedtobeoverrideninuserclasses
/**
*
*@param mixed
*@return object DomNode
*@access private
*/
functioninsertNewResult(&$metadata)
{
if($this->xmlroot)
return$this->xmlroot->new_child($this->tagNameResult,NULL);
else
{
$this->xmlroot=$this->xmldoc->add_root($this->tagNameResult);
//PHP4.0.6had$root->nameastagname,checkforthathere...
if(!isset($this->xmlroot->{$this->tagname}))
{
$this->tagname="name";
}
return$this->xmlroot;
}
}
/**
* tobewritten
*
*@param objectDomNode$parent_row
*@param mixed$res
*@param mixed$key
*@param mixed&metadata
*@return objectDomNode
*@accessprivate
*/
functioninsertNewRow($parent_row,$res,$key,&$metadata)
{
return $parent_row->new_child($this->tagNameRow,Null);
}
/**
* tobewritten
*
*@param objectDomNode$parent
*@param mixed$res
*@param mixed$key
*@param mixed&$metadata
*@param mixed&$subrow
*@return objectDomNode
*@accessprivate
*/
functioninsertNewElement($parent,$res,$key,&$metadata,&$subrow)
{
return $parent->new_child($metadata[$key]["name"],$this->xml_encode(trim$res[$key]));
}
/**
* tobewritten
*
*@param mixed$key
*@param mixed$value
*@param mixed&$metadata
*@accessprivate
*/
functionaddTableInfo($key,$value,&$metadata){
}
//endfunctions,whichareintendedtobeoverrideninuserclasses
//herecomesomehelperfunctions...
/**
*makeutf8outoftheinputdataandescape&with&and"<"with"<"
*(weassumethatwhenthere"snospaceafter<it"satag,whichweneedinthexml)
* I"mnotsure,ifthisisthestandardway,butitworksforme.
*
*@param stringtexttobeutfed.
*@accessprivate
*/
functionxml_encode($text)
{
if(function_exists("iconv")&&isset($this->encoding_from)&&isset($this->encoding_to))
{
ini_set("track_errors",1);
$text=iconv($this->encoding_from,$this->encoding_to,ereg_replace("&","&",ereg_replace("<","<",$text)));
if(!isset($text))
{
if(isset($php_errormsg))
{
$errormsg="error:$php_errormsg";
}
else
{
$errormsg="undefinediconverror,turnontrack_errorsinphp.initogetmoredetails";
}
returnPEAR::raiseError($errormsg,Null,PEAR_ERROR_DIE);
}
else{
return$text;
}
}
else
{
//$text=utf8_encode(ereg_replace("&","&",ereg_replace("<","<",$text)));
$text=trim(ereg_replace("&","&",ereg_replace("<","<",$text)));
// echo$text;
}
return$text;
}
//takenfromkc@hireability.comathttp://www.php.net/manual/en/function.array-merge-recursive.php
/**
*Thereseemedtobenobuiltinfunctionthatwouldmergetwoarraysrecursivelyandclobber
* anyexistingkey/valuepairs.Array_Merge()isnotrecursive,andarray_merge_recursive
* seemedtogiveunsatisfactoryresults...itwouldappendduplicatekey/values.
*
* Sohere"sacrossbetweenarray_mergeandarray_merge_recursive
**/
/**
*
*@param arrayfirstarraytobemerged
*@param arraysecondarraytobemerged
*@return arraymergedarray
*@accessprivate
*/
functionarray_merge_clobber($a1,$a2)
{
if(!is_array($a1)
!is_array($a2))returnfalse;
$newarray=$a1;
while(list($key,$val)=each($a2))
{
if(is_array($val)&&is_array($newarray[$key]))
{
$newarray[$key]=$this->array_merge_clobber($newarray[$key],$val);
}
else
{
$newarray[$key]=$val;
}
}
return$newarray;
}
/**
*Addsaxmlstringto$this->xmldoc.
*It"sinsertedonthesamelevelasa"normal"resultset,meansjustasachildrenof<root>
*ifaxpathexpressionissupplied,ittakesthatforselectingonlypartofthexml-file
*
*thecleancodeworksonlywithphp4.0.7
*forphp4.0.6:
*Ifoundnocleanermethodthanthebelowone.it"smaybenasty(xmlObject->string->xmlObject),
* butitworks.IfsomeoneknowshowtoaddwholeDomNodestoanotherone,letmeknow...
*
*@param stringxmlstring
*@param mixedxpath eitherastringwiththexpathexpressionoranarraywith"xpath"=>xpathexpression and"root"=tag/subtag/etc,whicharethetagstobeinsertedbeforetheresult
*@accessprivate
*/
functiondoXmlString2Xml($string,$xpath=Null)
{
//checkifwehavearecentdomxml.otherwiseusetheworkaround...
$version=explode(".",phpversion());
if(!($version[0]<=4and$version[1]<=0and$version[2]<7)){
if(is_array($xpath))
{
if(isset($xpath["root"]))
{
$root=$xpath["root"];
}
$xpath=$xpath["xpath"];
}
$tmpxml=xmldoc($string);
$subroot=$this->xmlroot;
if(isset($root))
{
$roots=explode("/",$root);
foreach($rootsas$rootelement)
{
if(strlen($rootelement)>0)
{
$subroot=$subroot->new_child($rootelement,"");
}
}
}
//$this->xmlroot->addchilddoessomestrangethingswhenaddednodesfromxpath....sothiscommenthelpsout
$newchild=$subroot->add_child($this->xmldoc->create_comment("thepurposeofthiscommentisaworkaroundinsql2php.phpline".__LINE__));
//ifnoxpathisgiven,justtakethewholefile
if((is_null($xpath)))
{
$newchild->append_child($tmpxml->root());
}
else
{
$xctx=$tmpxml->xpath_new_context();
$xnode=xpath_eval($xctx,$xpath);
foreach($xnode->nodesetas$node)
{
$newchild->append_child($node);
}
}
}
else{
$MainXmlString=$this->xmldoc->dumpmem();
$string=preg_replace("/<\?xml.*\?>/","",$string);
$MainXmlString=preg_replace("/<".$this->xmlroot->{$this->tagname}."\/>/","<".$this->xmlroot->{$this->tagname}."></".$this->xmlroot->{$this->tagname}.">",$MainXmlString);
$MainXmlString=preg_replace("/<\/".$this->xmlroot->{$this->tagname}.">/",$string."</".$this->xmlroot->{$this->tagname}.">",$MainXmlString);
$this->xmldoc=xmldoc($MainXmlString);
$this->xmlroot=$this->xmldoc->root();
}
}
/**
*setstheencodingforthedb2xmltransformation
*@param string$encoding_fromencodingtotransformfrom
*@param string$encoding_toencodingtotransformto
*@accesspublic
*/
functionsetEncoding($encoding_from="ISO-8859-1",$encoding_to="UTF-8")
{
$this->encoding_from=$encoding_from;
$this->encoding_to=$encoding_to;
}
/**
*@paramarray$parentTablesparenttochildrelation
*@accesspublic
*/
functionSetParentTables($parentTables)
{
foreach($parentTablesas$table=>$parent)
{
$table_info["parent_table"][$table]=$parent;
}
$this->SetOptions(array("user_tableInfo"=>$table_info));
}
/**
*returnsthecontentofthefirstmatchofthexpathexpression
*
*@param string$exprxpathexpression
*@return mixedcontentoftheevaluatedxpathexpression
*@access public
*/
functiongetXpathValue($expr)
{
$xpth=$this->xmldoc->xpath_new_context();
$xnode=xpath_eval($xpth,$expr);
if(isset($xnode->nodeset[0]))
{
$firstnode=$xnode->nodeset[0];
$children=$firstnode->children();
$value=$children[0]->content;
return$value;
}
else
{
returnNull;
}
}
/**
*getthevaluesasanarrayfromthechildtagsfromthefirstmatchofthexpathexpression
*
*@param stringxpathexpression
*@return arraywithkey->valueofsubtags
*@access public
*/
functiongetXpathChildValues($expr)
{
$xpth=$this->xmldoc->xpath_new_context();
$xnode=xpath_eval($xpth,$expr);
if(isset($xnode->nodeset[0]))
{
foreach($xnode->nodeset[0]->children()as$child)
{
$children=$child->children();
$value[$child->{$this->tagname}]=$children[0]->content;
}
return$value;
}
else
{
returnNull;
}
}
}
?>