473,657 Members | 2,481 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getEleme ntsByTagName("r esults")[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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getEleme ntsByTagName("r esults")[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 4114
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*******@goog lemail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getEleme ntsByTagName("r esults")[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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getEleme ntsByTagName("r esults")[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.co m> wrote in message
news:tv******** **********@torn ado.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*******@goog lemail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getEleme ntsByTagName("r esults")[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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getEleme ntsByTagName("r esults")[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($xmlMa rkup)) {
echo 'Number of child nodes: ' .
$xmlDocument->documentElemen t->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().par seFromString([
'<parent>',
' <child1/>',
' <child2/>',
' <child3/>',
'</parent>'
].join('\r\n'), 'application/xml');

alert(xmlDocume nt.documentElem ent.childNodes. length);

there alerts 7.

The same with Opera 9.
Does every XML parser in the world include the Java parser that guy
<http://groups.google.c om/group/comp.lang.java. programmer/msg/b2073fbf8a38066 9?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.co m> wrote in message
news:tv******** **********@torn ado.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*******@goog lemail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>CDATA

xmldoc.getEleme ntsByTagName("r esults")[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.getEleme ntsByTagName("r esults")[0].childNodes[0].nodeType -->
MN=>TEXT,IE =>TEXT
xmldoc.getEleme ntsByTagName("r esults")[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**********@gm ail.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**********@gm ail.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
programmaticall y-wise correct at
<http://bugzilla.mozill a.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 "TreeWalker s" 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
4014
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 explorer-does anyone know how to solve that problem??
2
7073
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 in the form of XHTML in an XML document (which, in turn, is stored in an XML database). So far so good. However the editing tool must allow users to paste in the contents of MS Word documents. I soon discovered that Word does not generate...
6
2827
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 and adjust to the newly added items like it does in iE. It just occured to me that i dont really have to use a span, and a html <hr> tag could do the trick -I will go try. But aside from that could some one explain why this occurs? And will I get...
10
2334
by: Simon Brooke | last post by:
Here's my problem: <xsl:template match="/category"> .... <script type="text/javascript"> &lt;!]&gt; </script> .... </xsl:template>
8
2278
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 receives a variable which basically encapsulates this: <div id="tableid"> <tr>
5
22499
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
17535
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 html, I can put this in a CDATA section with PHP, but how do I retrieve that information with Javascript and put the HTML in a div ? thanx, Pugi!
7
3972
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
7578
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 void Button2_Click(object sender, EventArgs e)
0
8394
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8306
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7327
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.