The short answer is that if you are only using this code on Node, then you are free to use either node.toString()
or new XMLSerializer().serializeToString(node)
.
The toString
method is however non-standard, and does not exist in browsers. The DOMParser spec only specifies the parsing/serializing in a few ways and toString
is not one of them. As you can see in XMLDOM
, it is just an alias to serializeToString
:
https://github.com/jindw/xmldom/blob/master/dom.js#L911
Also note that serializeToString
does not have a second argument, so you don't need the second text/xml
.