Problems with DOM Parsing/Serialization and character encodings?

[email protected] (Matthew Wilson)
Newsgroups gmane.comp.mozilla.devel.xml
Organization http://groups.google.com
Message-ID <[email protected]>
Are there any issues using Mozilla DOM Parsing or Serialization and
character encodings?

For example, using Cyrillic characters via numeric entity references
(I hope I have that term correct) in an ISO-8859-1 document:

   var text = "&#1042;&#1099;&#1073;&#1088;&#1072;&#1090;&#1100;";
   var xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n<test>" +
text + "</test>";
   window.alert (xml);

This outputs the string exactly as you would expect, with the numeric
characters intact.

If I then make an XMLDocument out of the text, and print the value of
the text node:

   var originalDoc = new DOMParser().parseFromString(xml, "text/xml");
   window.alert (originalDoc.documentElement.childNodes[0].data);

then I see the actual Cyrillic characters. I'll paste them in here,
but I don't know how successful that will be:
&#1042;&#1099;&#1073;&#1088;&#1072;&#1090;&#1100;

I think that's still correct.

Then if I serialize it back to a string and print the result, the
numeric character entity references are gone, I still have the
Cyrillic characters, and the XML declaration still has an encoding of
ISO-8859-1:

   var serializedDoc = new XMLSerializer().serializeToString
(originalDoc);
   window.alert (serializedDoc);

<?xml version="1.0" encoding="ISO-8859-1"?>
<test>&#1042;&#1099;&#1073;&#1088;&#1072;&#1090;&#1100;</test>

That looks wrong to me. Any opinions?

Matthew Wilsno
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.