4
votes

I'm using XMLSerializer() to output an in-memory XML document, however it seems to 'entitizing' elements using XHTML standard entities like &nbsp ; . I want to produce an XML document without XHTML entites.

My target DTD does not define these entities, so if a user happens to input a character w/ a corresponding XHTML entity, the serialized document is not well-formed (references an undefined entity like &nsbp;)

Maybe I'm building the DOM tree incorrectly? Or is there another way to avoid XMLSerializer() behaving as if it were XHTMLSerializer()?

1
Maybe you could include a jsfiddle with an example of the XML you are trying to serialize. What you are describing should only happen, if you have <html xmlns="w3.org/1999/xhtml"> or the DOCTYPE set to use XHTML. - matt snider
I have a similar problem. Did you find a solution? - Alexander Stolz
Nope, didn't figure this out. - Seth

1 Answers

0
votes

worksforme in Firefox 38:

new XMLSerializer().serializeToString(document.createRange()
    .createContextualFragment('<div foo="bar&quot;bar">&nbsp;&uuml;</div>'))

result:

"<div xmlns="http://www.w3.org/1999/xhtml" foo="bar&quot;bar"> ΓΌ</div>"

Only standard XML entities and utf-8.