我有以下PHP代码。XSL转换工作正常,并向服务器回显字符串,但是当我尝试保存时,得到"致命错误:调用未定义的方法stdClass::save()"。使用PHP 5.3简单的问题吗?
<?php
$xml = new DOMDocument;
$xml->load('myxml.xml');
$xsl = new DOMDocument;
$xsl->load('myxsl.xsl');
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$newXml = $proc->transformToXML($xml);
$newXML->formatOutput=true;
echo $newXml;
$newXML->save("newfile.xml")or die("Error");
?>
transformToXML()返回字符串。当然,您可以使用file_put_contents()
将该字符串存储在文件中,但是您可以直接使用:
$proc->transformToURI($xml,'file://'.getcwd().'/newfile.xml');
. .(= getcwd()
)。
如果你想在保存之前设置一些属性/做一些修改,你可能想:
$newDOM = $proc->transformToDoc($xml);
$newDOM->formatOutput = true;
$newDOM->save("newfile.xml")