【问题标题】:save XSL output to XML with PHP使用 PHP 将 XSL 输出保存到 XML
【发布时间】:2013-06-12 13:57:23
【问题描述】:

我有以下 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");
?>

【问题讨论】:

    标签: php xml xslt


    【解决方案1】:

    transformToXML() 返回一个字符串。您当然可以使用file_put_contents() 将该字符串存储在文件中,但是您可以直接使用:

     $proc->transformToURI($xml,'file://'.getcwd().'/newfile.xml');
    

    .. 或除当前工作目录之外的任何其他目录 (=getcwd())。

    如果你想在保存之前设置一些属性/做一些修改,你可能想要:

    $newDOM = $proc->transformToDoc($xml);
    $newDOM->formatOutput = true;
    $newDOM->save("newfile.xml")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-18
      • 2014-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多