Last active
February 21, 2023 15:30
-
-
Save JamesTheAwesomeDude/a072e2378ddc34a52abae4f29a774a7c to your computer and use it in GitHub Desktop.
Firefox/Chrome DOM stdlib: create XML document from scratch, including declaration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example: createXMLDocumentWithDeclaration('http://www.topografix.com/GPX/1/1', 'gpx', null, 'version="1.0" standalone="yes"') | |
function createXMLDocumentWithDeclaration(namespaceURI, qualifiedNameStr, documentType=null, declarationData='version="1.0"') { | |
const document = new Document().implementation.createDocument(namespaceURI, qualifiedNameStr, documentType); | |
// https://www.w3.org/TR/xml/#NT-XMLDecl | |
document.insertBefore(document.createProcessingInstruction("xml", declarationData), document.firstChild); | |
return document; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment