Unable to round-trip tab character using XMLHttpRequest and XMLSerializer
"Mark A. Ziesemer" <[email protected]> Sat, 29 Sep 2007 21:55:12 -0500
| Newsgroups | gmane.comp.mozilla.devel.xml |
|---|---|
| Message-ID | <[email protected]> |
Use case:
Assume JavaScript in a Mozilla Firefox extension.
1) Create or open a new XML document for modification using DOM.
2) Set an XML attribute value containing a tab character. e.g.,
node.setAttribute("someName", "some /t Value");
3) Save the XML using XMLSerializer.
4) Re-read the XML using XMLHttpRequest.
The problem is that this currently would be read back in as "some Value"
instead of "some /t Value".
Verified that the saved XML contains 13 characters, including
[space,tab,space].
Missing the tab when reading this is somewhat expected, per what I
understand of the W3C specification regarding attribute normalization:
http://www.w3.org/TR/2000/REC-xml-20001006#sec-white-space
When manually changing the saved XML to instead use a character entity
("some 	 Value"), the read from XMLHttpRequest works as desired,
returning "some /t Value" for the "someName" attribute.
I am unable to determine how to save values with character entities
using XMLSerializer. It properly escapes values such as '&', replacing
it with "&". However, as such, trying to save "	" results in
the entity being escaped "&#09;". This should be expected, but the
question remains: How can a character entity be written using XMLSerializer?
(I just verified that using Apache Xalan-J (the default JAXP transformer
under Java 6) serializes '/t' using a character entity.)
--
Mark A. Ziesemer
www.ziesemer.com