Re: Unable to round-trip tab character using XMLHttpRequest and XMLSerializer

"Mark A. Ziesemer" <[email protected]> Mon, 01 Oct 2007 07:32:13 -0500
Newsgroups gmane.comp.mozilla.devel.xml
Message-ID <[email protected]>
Boris Zbarsky wrote:
> You have to use &amp; to get well-formed XML out, basically.  The 
> default serialization mode is to use as few entities as possible while 
> still producing a correct and valid serialization of the DOM.
> 
> If this process is lossy for the tab character in XML because the XML 
> parser normalizes away literal tabs, then a bug should be filed on 
> changing how it's handled.

Now that we've pretty much confirmed that round-tripping tab characters 
is pretty much impossible, I probably will open a bug report, at least 
for tracking purposes in case others are running into similar issues.

> For what you're doing, why not just serialize directly into a text 
> file?  It doesn't sound like you're starting with XML, right?  So why 
> try to shoehorn your data into XML, with its funny whitespace rules?

This is just one of many other data elements I'm saving.  Its working 
great for everything else.  I can then also use XPath against it for 
searching later.

> Alternately, you could base64-encode your data to eliminate any 
> possibly-problematic characters.

I probably will just use some XML related workaround - base64, CDATA, or 
otherwise.  Following XML ideals, I'd actually split up the tabbed 
fields and store them as separate XML entities - though not doing so 
makes the code more resilient to change if the data format is added to.

>> Unfortunately, your suggestion to use nsIDocumentEncoder seems much 
>> easier said than done.  Searching for "nsIDocumentEncoder" or even 
>> "DocumentEncoder" on the MDC Wiki currently yields 0 results.
> 
> You can't use it from script in Firefox 2 anyway.  I keep forgetting 
> that not everyone is working against the trunk...

Thanks for that time-saving note!  :-)  Like I said above, I'll just use 
an XML workaround for now.  Yeah, even working from trunk and the alpha 
builds may be preferred for developers, for the latest features and 
fixes, but that's quite a minimum dependency for an extension!  :-)

Thanks for all the information!