0

I have the following PHP code. The XSL transformation works fine, and echoes a string fine to the server, but when I try to save, I get "Fatal error: Call to undefined method stdClass::save()" Using PHP 5.3 Simple problem?

<?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");
?>

1 Answer 1

1

transformToXML() returns a string. You can of course use file_put_contents() to store that string in a file, you can however do it directly with:

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

.. or any other directory then the current working dir (=getcwd()).

If you want to set some properties / do some tinkering before saving, you might want to:

$newDOM = $proc->transformToDoc($xml);
$newDOM->formatOutput = true;
$newDOM->save("newfile.xml")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.