对于后续代码,当我放
$doc = new DomDocument('1.0');
我在 DOMDocument::saveXML() xmlEscapeEntities 中收到警告:字符超出范围
当我把
$doc = new DomDocument('1.0','UTF-8');
我在 $xmldoc = DOMDocument::loadXML($xml);
有代码
function readXsltTemplateAdmin($XsltFileName,$arrData,$params="",$other="",$number="")
{
// kreate XML from array
/** primer:
* $xml = <<<EOB
* <alldata>
* <datarow>
* <name>sasa</name>
* <comment>aab</comment>
* </datatrow>
* <datatrow>
* <name>dragana</name>
* <comment>eeeee</comment>
* </commentrow>
* </alldata>
* EOB;
*/
$doc = new DomDocument('1.0','UTF-8');
//$doc = new DomDocument('1.0');
// root
$root = $doc->createElement('alldata'.$number);
$root = $doc->appendChild($root);
if (is_array($other) || is_array($params))
{
if($other!="")
{
foreach($other as $k => $v)
{
$child = $doc->createElement($k);
$child = $root->appendChild($child);
$value = $doc->createTextNode($v);
$value = $child->appendChild($value);
}
}
foreach($params as $ParamKey => $ParamValue)
{
$child = $doc->createElement($ParamKey);
$child = $root->appendChild($child);
$value = $doc->createTextNode($ParamValue);
$value = $child->appendChild($value);
}
}
if (sizeof($arrData)>0)
{
for ($i=0;$i<sizeof($arrData);$i++) {
$occ = $doc->createElement("datarow");
$occ = $root->appendChild($occ);
foreach ($arrData[$i] as $fieldname => $fieldvalue) {
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
$value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
}
}
$xml = $doc->saveXML();
$handle = fopen($XsltFileName, "r");
$xsl = fread($handle, filesize($XsltFileName)) or die();
fclose($handle);
$xmldoc = DOMDocument::loadXML($xml);
$xsldoc = DOMDocument::loadXML($xsl);
$proc = new XSLTProcessor() ;
$proc->registerPHPFunctions();
$proc->importStyleSheet($xsldoc);
$output=$proc->transformToXML($xmldoc);
return $output;
}