Using the XMLSerializer () Browser to Create XML Without XHTML Objects

I use XMLSerializer () to output an XML document in memory, however it seems to β€œgive” elements using standard XHTML objects such as & nbsp ;, I want to create an XML document without XHTML authority .

My target DTD does not define these entities, therefore, if the user enters the w / character of the corresponding XHTML object, the serialized document is not correct (refers to an undefined object such as & nsbp;)

Perhaps I am creating the DOM tree incorrectly? Or is there another way to avoid using XMLSerializer (), as if it were XHTMLSerializer ()?

+4
source share
1 answer

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 and utf-8 objects.

0
source

All Articles