views:

77

answers:

1

I am trying to save a string of html into the nodeValue attribute of a DOMElement in PHP, but after I save the file with DOMDocument->saveHTMLFile the string of HTML is escaped and I can not figure out how to get the string not be saved as escaped text. Any ideas?

A: 

You should load that string of html with DOMDocument::loadHTML and append that to your node (appendChild).

Qwerty
This seems to be what I would be looking to do, after I parse the HTML string with loadHTML I am then trying to append it to the current element with this: $currElement->appendChild($html_dom_doc->documentElement) But I am getting an exception: Fatal error: Uncaught exception 'DOMException' with message 'Wrong Document Error'
trobrock
You can use importNode() method:http://en.php.net/manual/en/domdocument.importnode.phpAlso, PHP's DOM has non-standard appendXML() method, it looks exactly what you need (not sure it will accept HTML, though).Link with example:http://en.php.net/manual/en/domdocumentfragment.appendxml.php
Qwerty
I used the importNode method and it is seeming to work
trobrock