0

Okay, hopefully I didn't miss a thread that is making this a duplicate. Everything I found was about AJAX requests with jQuery, whereas I'm not working with AJAX, and I'm using native JS.

Basically, I'm creating a DOM parser, and then an XML document from that.

var parser = new DOMParser();
var doc = parser.parseFromString(HTML, "text/xml");

Once I do my manipulation, I need to XML as a string, not an object.

In Chrome, I can just do doc.innerHTML, but IE doesn't even have an innerHTML attribute, which makes sense since it is XML and not HTML.

I know I can create a new node, and copy all children over to that, then get the innerHTML, but is there a better / faster way than that to just get the string representation of an XML document?

7
  • Presumably HTML is the string you are parsing, is it HTML or XML? You can also use XMLSerializer for serialising the DOM. IE (i.e. Microsoft) invented innerHTML, it's been standardised by the W3C, MS might not have kept up. Commented Jan 7, 2015 at 0:58
  • .innerHTML doesn't make much sense for non-HTML XML Commented Jan 7, 2015 at 1:14
  • @RobG, You are corrent, HTML is the string to be parsed, and it is HTML. The reason I'm using text/xml is because IE doesn't support text/html far enough back. But everything is valid HTML Commented Jan 7, 2015 at 1:15
  • 1
    It seems XMLSerializer is available in IE 9+, so maybe you only need the div hack for IE 8? Feature test for support and fallback if required. Commented Jan 7, 2015 at 1:54
  • 1
    @user31571297 this question was for Internet Explorer, not edge. That is not the same question. Commented Nov 9 at 21:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.