Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16119

Re: Diactric in CDATA in XML reponse

Message-ID <35486874.FMhRtqDPO2@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-09-22 16:46 +0200
Subject Re: Diactric in CDATA in XML reponse
Newsgroups comp.lang.javascript
References <505cc8dc$0$6885$e4fe514c@news2.news.xs4all.nl> <1621260.MulQa8nmlF@PointedEars.de> <505db945$0$6958$e4fe514c@news2.news.xs4all.nl>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Tom de Neef wrote:

> "Thomas 'PointedEars' Lahn wrote:
>>> I encounter a situation where the responseXML of a XMLHttpRequest
>>> contains a CDATA element, like:
>>>
>>> <xml><mod><![CDATA[some text]]></mod></xml>
>>>
>>> This is used to load data in a table. It works always in FF and in
>>> Chrome.
>>> But in IE8 the table is not always loaded.
>>> It took me a while to find that the problem is related to the presence
>>> of a diacritic (ASCII>128) in the CDATA text block. In such cases the
>>> responseXML is returned by IE with firstChild=null.
>>
>> It might be helpful for further diagnosis that the referred document
>> object implements the IXMLDOMDocument interface which provides an `xml'
>> property for its XML serialization. [1]
> 
> I guess it does:
>   var asyncRequestor = new XMLHttpRequest();

Refuse the temptation to guess.

>>> My question is how to handle this. I presume that I need to specify the
>>> encoding somewhere.
>>
>> Make sure that your XML data uses one of the character encodings that XML
>> applications must support (UTF-8 and UTF-16), or declare the used
>> character encoding. [2]  Not doing that and having incompatible code
>> sequences in the XML data leads to the XML document being empty.
>>
>> Generally, UTF-8 is the best choice for XML data because it can encode
>> all Unicode characters without using character references (such as
>> &#x20AC; for the Euro sign), is widely supported, and in most cases has
>> the smallest footprint while having all these properties.
> 
> I have added encoding so that the xml string no reads
> <xml>
>   <?xml version="1.0" encoding="utf-8" ?>
>   <mod><![CDATA[some text]]></mod>
> </xml>
> 
> This seems to work!

That would be negatively surprising, since it is _not_ Valid.  AISB, the 
declaration must come *before* the root element (here: `xml'), and declaring 
UTF-8 is not necessary because it is one of the defaults.  What matters is 
that the encoding declaration, if any, matches the encoding of the data.
I can see no relevant change there.

> Thank you.

You are welcome, but you are _not_ done there yet.


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Diactric in CDATA in XML reponse "Tom de Neef" <tdeneef@qolor.nl> - 2012-09-21 22:06 +0200
  Re: Diactric in CDATA in XML reponse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-22 03:46 +0200
    Re: Diactric in CDATA in XML reponse "Tom de Neef" <tdeneef@qolor.nl> - 2012-09-22 15:12 +0200
      Re: Diactric in CDATA in XML reponse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-22 16:46 +0200
        Re: Diactric in CDATA in XML reponse "Tom de Neef" <tdeneef@qolor.nl> - 2012-09-22 19:31 +0200
          Re: Diactric in CDATA in XML reponse Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-22 21:12 +0200

csiph-web