Skip to content

Instantly share code, notes, and snippets.

@xulapp
Created February 28, 2010 13:37
Show Gist options
  • Save xulapp/317586 to your computer and use it in GitHub Desktop.
Save xulapp/317586 to your computer and use it in GitHub Desktop.
xml2dom
function xml2dom(xml, doc) {
xml = <root xmlns={ doc.documentElement.namespaceURI }/>.appendChild(xml);
var settings = XML.settings();
XML.prettyPrinting = false;
var root = new DOMParser().parseFromString(xml.toXMLString(), 'application/xml').documentElement;
XML.setSettings(settings);
doc.adoptNode(root);
var range = doc.createRange();
range.selectNodeContents(root);
var frag = range.extractContents();
range.detach();
return frag.childNodes.length < 2 ? frag.firstChild : frag;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment