This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > March 2004 > xmlhttp and responseXML failing to read if CDATA section present





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author xmlhttp and responseXML failing to read if CDATA section present
Jiho Han

2004-03-30, 10:14 pm

I am trying to read the response through responseXML and whenever the
response XML contains a CDATA section it won't parse. I've seen posts on
the web where character encoding might present some issues but I'm just a
little confused.
The response would be something very innocuous:

<result>
<code>1</code>
<details><![CDATA[test]]></details>
</result>

If the details node contains the word "test" without CDATA surrounding it,
it will parse fine.
Anyone know what's going on?

Thanks much.
Jiho


Martin Honnen

2004-03-30, 10:14 pm



Jiho Han wrote:

> I am trying to read the response through responseXML and whenever the
> response XML contains a CDATA section it won't parse. I've seen posts on
> the web where character encoding might present some issues but I'm just a
> little confused.
> The response would be something very innocuous:
>
> <result>
> <code>1</code>
> <details><![CDATA[test]]></details>
> </result>
>
> If the details node contains the word "test" without CDATA surrounding it,
> it will parse fine.
> Anyone know what's going on?


I have saved your XML example and then script it as follows

var httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
httpRequest.open('GET', 'test20040327.xml', true);

httpRequest.onreadystatechange = function (evt) {
if (httpRequest.readyState == 4) {
var xmlDocument = httpRequest.responseXML;
var details = xmlDocument.getElementsByTagName('details')[0];
alert(details.firstChild.nodeType);
}
};

httpRequest.send(null);

and I do not get a parse error and the nodeType is correctly shown as 4
for CDATA section node.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jiho Han

2004-03-30, 10:14 pm

I have to apologize Martin, as I found in my code a missing closing "]" for
the CDATA section. I guess I was too quick to post and/or have eyes that
deceive me. :)

Thanks for your help though.
Jiho

"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:Orb%23%23K$EEHA.3256@TK2MSFTNGP09.phx.gbl...
>
>
> Jiho Han wrote:
>
on[color=darkred]
a[color=darkred]
it,[color=darkred]
>
> I have saved your XML example and then script it as follows
>
> var httpRequest = new ActiveXObject('Msxml2.XMLHTTP');
> httpRequest.open('GET', 'test20040327.xml', true);
>
> httpRequest.onreadystatechange = function (evt) {
> if (httpRequest.readyState == 4) {
> var xmlDocument = httpRequest.responseXML;
> var details = xmlDocument.getElementsByTagName('details')[0];
> alert(details.firstChild.nodeType);
> }
> };
>
> httpRequest.send(null);
>
> and I do not get a parse error and the nodeType is correctly shown as 4
> for CDATA section node.
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
>



Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews