答案: {
$this->doXmlString2Xml($string,$xpath);
}
/**
* Adds an additional pear::db_result resultset to $this->xmldoc
*
* @param Object db_result result from a DB-query
* @see doSql2Xml()
* @access public
*/
function addResult($result)
{
$this->doSql2Xml($result);
}
/**
* Adds an aditional resultset generated from an sql-statement
* to $this->xmldoc
*
* @param string sql a string containing an sql-statement.
* @access public
* @see doSql2Xml()
*/
function addSql($sql)
{
/* if there are {} expressions in the sql query, we assume it's an xpath expression to
* be evaluated.
*/
if (preg_match_all ("/\{([^\}]+)\}/i",$sql,$matches))
{
foreach ($matches[1] as $match)
{
$sql = preg_replace("#\{".preg_quote($match)."\}# ", $this->getXpathValue($match),$sql);
}
}
$result = $this->db->query($sql);
//very strange
if (PEAR::isError($result->result)) {
print "You have an SQL-Error:<br>".$result->result->userinfo;
print "<br>";
new DB_Error($result->result->code,PEAR_ERROR_DIE);
}
$this->doSql2Xml($result);
}
/**
* Adds an aditional resultset generated from an Array
* to $this->xmldoc
* TODO: more explanation, how arrays are transferred
*
* @param array multidimensional array.
* @access public
* @see doArray2Xml()
*/
function addArray ($array)
{
$parent_row = $this->insertNewResult(&$metadata);
$this->DoArray2Xml($array,$parent_row);
}
/**
* Returns an xml-string with a xml-representation of the resultsets.
*
* The resultset can be directly provided here, or if you need more than one
* in your xml, then you have to provide each of them with add() before you
* call getXML, but the last one can also be provided here.
*
* @param mixed $result result Object from a DB-query
* @return string xml
* @access public
*/
function getXML($result = Null)
{
$xmldoc = $this->getXMLObject($result);
return $xmldoc->dumpmem();
}
/**
* Returns an xml DomDocument Object with a xml-representation of the resultsets.
*
* The resultset can be directly provided here, or if you need more than one
* in your xml, then you have to provide each of them with add() before you
* call getXMLObject, but the last one can also be provided here.
*
* @param mixed $result result Object from a DB-query
* @return Object DomDocument
* @access public
*/
function getXMLObject($result = Null)
{
if ($result) {
$this->add ($result);
}
return $this->xmldoc;
}
/**
* For adding db_result-"trees" to $this->xmldoc
* @param Object db_result
* @access private
* @see addResult(),addSql()
*/
function doSql2Xml($result)
{
if (DB::IsError($result)) {
print "Error in file ".__FILE__." at line ".__LINE__."<br>\n";
print $result->userinfo."<br>\n";
new DB_Error($result->code,PEAR_ERROR_DIE);
}
// the method_exists is here, cause tableInfo is only in the cvs at the moment
// BE CAREFUL: if you have fields with the same name in different tables, you will get errors
// later, since DB_FETCHMODE_ASSOC doesn't differentiate that stuff.
$this->LastResult = &$result;
if (!method_exists($result,"tableInfo") || ! ($tableInfo = $result->tableInfo(False)))
上一个:VML绘图板②脚本--VMLgraph.js、XMLtool.js
下一个:DOMXML函数笔记