const s = new XMLSerializer();
const str = s.serializeToString(document);
saveXML(str);XMLSerializer / notebook
XMLSerializer
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
const inp = document.createElement("input");
const XMLS = new XMLSerializer();
const inpSerialized = XMLS.serializeToString(inp); // First convert DOM node into a string
// Insert the newly created node into the document's body
document.body.insertAdjacentHTML("afterbegin", inpSerialized);