473,404 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

IE and Mozilla recognize CDATA nodetype differently

Hi Folks
I am trying to access an HTML code stored as CDATA section in the xml
file listed bellow:

<?xml version="1.0"?>
<results count="5">
<![CDATA[
<table><tr><td>Hello World</td></tr></table>
]]>
</results>

The xml tree is the responseXML part of an XmlHttpRequest and is stored
in a the javascript object xmldoc. While trying to test the node type
of the children of the "results"-Element I got different results with
IE and Mozilla:

xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>NULL

I added a non empty text node to the result element:
<results count="5">
blalba text
<![CDATA[...

Now I get this:
xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>CDATA

Does someone have an explanation for this behaviour?

I am using Mozilla 1.5 and IE 6

Cheers,
Aziz

Feb 4 '06 #1
7 4102
Aziz -

You need to keep in mind that Mozilla has a very rough time conforming to
standards. Especially when dealing with XML. You will need to run a "fixer
utility" on your XML data before Mozilla can understand it. Here is the
problem:

<parent>
<child1/>
<child2/>
<child3/>
</parent>

What you have there is a parent with 3 children to every XML parser in the
world but Mozilla's. In Mozilla you have a parent with 7 children. Mozilla
treats each line break as a child. In order to combat this you need to loop
through every child and if the nodeType = 3 and the nodeName = '#text' and
the number of childNodes > 1 then you know that what you have there is a
fake child and you can remove that node.

~Digital~

"Aziz" <ra*******@googlemail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi Folks
I am trying to access an HTML code stored as CDATA section in the xml
file listed bellow:

<?xml version="1.0"?>
<results count="5">
<![CDATA[
<table><tr><td>Hello World</td></tr></table>
]]>
</results>

The xml tree is the responseXML part of an XmlHttpRequest and is stored
in a the javascript object xmldoc. While trying to test the node type
of the children of the "results"-Element I got different results with
IE and Mozilla:

xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>NULL

I added a non empty text node to the result element:
<results count="5">
blalba text
<![CDATA[...

Now I get this:
xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>CDATA

Does someone have an explanation for this behaviour?

I am using Mozilla 1.5 and IE 6

Cheers,
Aziz

Feb 4 '06 #2
To clarify it isn't the line break per se but any white space between tags
generates another child. e.e. <parent> <child>First Born</child>.... The
space between <parent> and <child> will give you that extra child node in
the XML parser.

"Digital" <re****@spam.com> wrote in message
news:tv******************@tornado.rdc-kc.rr.com...
Aziz -

You need to keep in mind that Mozilla has a very rough time conforming to
standards. Especially when dealing with XML. You will need to run a
"fixer utility" on your XML data before Mozilla can understand it. Here
is the problem:

<parent>
<child1/>
<child2/>
<child3/>
</parent>

What you have there is a parent with 3 children to every XML parser in the
world but Mozilla's. In Mozilla you have a parent with 7 children.
Mozilla treats each line break as a child. In order to combat this you
need to loop through every child and if the nodeType = 3 and the nodeName
= '#text' and the number of childNodes > 1 then you know that what you
have there is a fake child and you can remove that node.

~Digital~

"Aziz" <ra*******@googlemail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi Folks
I am trying to access an HTML code stored as CDATA section in the xml
file listed bellow:

<?xml version="1.0"?>
<results count="5">
<![CDATA[
<table><tr><td>Hello World</td></tr></table>
]]>
</results>

The xml tree is the responseXML part of an XmlHttpRequest and is stored
in a the javascript object xmldoc. While trying to test the node type
of the children of the "results"-Element I got different results with
IE and Mozilla:

xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>NULL

I added a non empty text node to the result element:
<results count="5">
blalba text
<![CDATA[...

Now I get this:
xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>CDATA

Does someone have an explanation for this behaviour?

I am using Mozilla 1.5 and IE 6

Cheers,
Aziz


Feb 4 '06 #3


Digital wrote:

You need to keep in mind that Mozilla has a very rough time conforming to
standards. Especially when dealing with XML.
Are you trolling?
Here is the
problem:

<parent>
<child1/>
<child2/>
<child3/>
</parent>

What you have there is a parent with 3 children to every XML parser in the
world but Mozilla's. In Mozilla you have a parent with 7 children.


Does "every XML parser in the world" include the DOM implementation in
PHP 5?

Doing

$xmlMarkup = <<<EOD
<parent>
<child1/>
<child2/>
<child3/>
</parent>
EOD;

$xmlDocument = new DOMDocument();
if ($xmlDocument->loadXML($xmlMarkup)) {
echo 'Number of child nodes: ' .
$xmlDocument->documentElement->childNodes->length;
}
else {
echo 'Parse error.';
}

there gives

Number of child nodes: 7
Does "every XML parser in the world" include the DOM implementation in
Opera 8? Doing

var xmlDocument = new DOMParser().parseFromString([
'<parent>',
' <child1/>',
' <child2/>',
' <child3/>',
'</parent>'
].join('\r\n'), 'application/xml');

alert(xmlDocument.documentElement.childNodes.lengt h);

there alerts 7.

The same with Opera 9.
Does every XML parser in the world include the Java parser that guy
<http://groups.google.com/group/comp.lang.java.programmer/msg/b2073fbf8a380669?hl=en&>
is using?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 4 '06 #4
Thanks for the help. I have modified my PHP server side code to provide
the xml response as a string with no \n or \r.

To clarify it isn't the line break per se but any white space between tags
generates another child. e.e. <parent> <child>First Born</child>.... The
space between <parent> and <child> will give you that extra child node in
the XML parser.

"Digital" <re****@spam.com> wrote in message
news:tv******************@tornado.rdc-kc.rr.com...
Aziz -

You need to keep in mind that Mozilla has a very rough time conforming to
standards. Especially when dealing with XML. You will need to run a
"fixer utility" on your XML data before Mozilla can understand it. Here
is the problem:

<parent>
<child1/>
<child2/>
<child3/>
</parent>

What you have there is a parent with 3 children to every XML parser in the
world but Mozilla's. In Mozilla you have a parent with 7 children.
Mozilla treats each line break as a child. In order to combat this you
need to loop through every child and if the nodeType = 3 and the nodeName
= '#text' and the number of childNodes > 1 then you know that what you
have there is a fake child and you can remove that node.

~Digital~

"Aziz" <ra*******@googlemail.com> wrote in message
news:11*********************@g44g2000cwa.googlegro ups.com...
Hi Folks
I am trying to access an HTML code stored as CDATA section in the xml
file listed bellow:

<?xml version="1.0"?>
<results count="5">
<![CDATA[
<table><tr><td>Hello World</td></tr></table>
]]>
</results>

The xml tree is the responseXML part of an XmlHttpRequest and is stored
in a the javascript object xmldoc. While trying to test the node type
of the children of the "results"-Element I got different results with
IE and Mozilla:

xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>NULL

I added a non empty text node to the result element:
<results count="5">
blalba text
<![CDATA[...

Now I get this:
xmldoc.getElementsByTagName("results")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getElementsByTagName("results")[0].childNodes[1].nodeType -->
MN=>CDATA,IE =>CDATA

Does someone have an explanation for this behaviour?

I am using Mozilla 1.5 and IE 6

Cheers,
Aziz



Feb 5 '06 #5
Hi all
After seeing all those problems with XML and Mozilla, I am just asking
myself , if Mozilla is
really that good Browser. In Order to be compatible with all Browsers,
I use now reponseText with AJAX to transport the http response and not
responseXML . I still can not imagine that Mozilla does not support
xmlResponse like IE.
Any idea?

Cheers
Aziz

Feb 7 '06 #6
az**********@gmail.com wrote:
[...]
After seeing all those problems with XML and Mozilla, I am just asking
myself , if Mozilla is
really that good Browser. [...]


You *are* trolling. FOAD.
PointedEars
Feb 16 '06 #7
VK

az**********@gmail.com wrote:
Hi all
After seeing all those problems with XML and Mozilla, I am just asking
myself , if Mozilla is really that good Browser.


Mozilla Foundation has nothing to do with the "unwanted nodes" problem.
They just strictly implement the relevant W3C standard.

By W3C an XML structure is being preserved in that exact state as it
came to you. By IE XML structure is being optimized by parser, which
means much lesser problems but the original XML changed.

There is a long lasting discussion about what is more
programmatically-wise correct at
<http://bugzilla.mozilla.org/show_bug.cgi?id=26179> where you are
welcome to join.

I'm not a participant of that discussion but I really like proposals to
make "exact nodes preservation" an option one would be able to turn on
and off.

The chances to have it ever blessed by W3C are very weak though, so all
kind of "TreeWalkers" still remain a must.

Feb 16 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

57
by: Piotr Wolski | last post by:
how to make my page that it was correct with every browser standard? for example when i change HTML's table size it has no effect when i see it under mozilla and has effect under Internet...
2
by: Dave Matthews | last post by:
Hi folks, I'm writing a web-page editing tool for my company which will allow staff (with no "technical" expertise) to maintain their own Intranet sites. The content for each webpage is stored...
6
by: hsomob1999 | last post by:
so i have a <ul> and I allow the user to append items to it. The problem is that on mozilla the <span class="line"> which is just a line to divide the sections gets overlaped and doesnt move down...
10
by: Simon Brooke | last post by:
Here's my problem: <xsl:template match="/category"> .... <script type="text/javascript"> &lt;!]&gt; </script> .... </xsl:template>
8
by: bennett.matthew | last post by:
Hello all, This is probably an elementary (no pun intended) question, but I've spent all afternoon on it and it's driving me crazy. I have a function which dynamically adds to a table. It...
5
by: Moses | last post by:
HI The Value for childNodes.length differs with mozilla and IE Is it problem with my coding..... I could not under stood............. The following is the details
2
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is...
7
by: Max | last post by:
Hello everyone! Can anyone help me to convert the CDATA expression "CDATA ::= (Char* - (Char* ']]>' Char*)" to Javascript Regular Expression? Thanks, Max
1
by: Dariusz Tomoń | last post by:
Hi, I have got xml document with CDATA sections containing special characters like links to images. All Iwant is to display the content in my div section. I tried like this: protected...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.