Convert HTMLDocument to printable string

I want to convert the Javascript DOM HTML to a string that I can write to a file. But how do you do the conversion of an HTMLDocument string to xml ?!

Refresh . If possible, I would like to see the html that is created after applying dynamic javascript rendering.

+3
source share
3 answers

DOM way to convert an HTMLDocument object to XML:

new XMLSerializer().serializeToString(oDocument);

There is no way in Internet Explorer to get the proper XML representation of an HTML document object by any built-in means. There you will need to implement the serialization mechanism yourself - traversing the DOM tree and creating an XML string.

+6
source
'<html>'+document.documentElement.innerHTML+'</html>'
+2

div node, HTMLDocument innerHTML div, ,

var div = document.createElement("div");
div.appendChild(oDocument);

console.log(div.innerHTML);
0

Source: https://habr.com/ru/post/1721738/


All Articles