473,382 Members | 1,386 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,382 software developers and data experts.

Need HELP: Firefox/nodeValue oddity

Hello,

When I try to insert this line of code into my script, Firefox refuses to
render. Could someone explain to me why that is?

if (x[i].firstChild.firstChild.nodeValue==productID) {
some code
}

full code listed below:

HTML BODY
===============================
<div id="writeroot"></div>
<script type="text/javascript">
importXML("prices.xml", priceTable, "kenko", "L37 Super PRO");
</script>
JAVASCRIPT
===============================
function importXML(xmlFile, xmlDisplay, para1, para2) {
if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) xmlDisplay(para1, para2);
}
} else if (document.implementation &&
document.implementation.createDocument) {
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = function() {
xmlDisplay(para1, para2);
}
} else {
alert('Sorry, your browser doesn't support XML scripting');
return;
}
xmlDoc.async = "false";
xmlDoc.load(xmlFile);
}

function priceTable(productCat, productID) {
var pCat = xmlDoc.getElementsByTagName(productCat);
var x = pCat[0].getElementsByTagName("item");

var newTable = document.createElement("table");
newTable.setAttribute("border",1);
var tableBody = document.createElement("tbody");
newTable.appendChild(tableBody);
var row = document.createElement("tr");
var emptyCell = document.createElement("th");
row.appendChild(emptyCell);
for (j=3; j<x[0].childNodes.length; j++) {
if (x[0].childNodes[j].nodeType != 1) continue;
var container = document.createElement("th");
var theData = document.createTextNode(x[0].childNodes
[j].nodeName.substring(1));
container.appendChild(theData);
row.appendChild(container);
}

tableBody.appendChild(row);

for (i=0; i<x.length; i++) {
var row = document.createElement("tr");
// if (x[i].firstChild.firstChild.nodeValue==productID) {
if (window.ActiveXObject) {
row.style.setAttribute("cssText", "background-color:
#cfc;");
} else if (document.implementation &&
document.implementation.createDocument) {
row.setAttribute("style", "background-color:
#cfc;");
}
// }
var nameCell = document.createElement("th");
var productName = document.createTextNode(x[i].childNodes
[1].firstChild.nodeValue);
nameCell.appendChild(productName);
row.appendChild(nameCell);
for (j=3; j<x[i].childNodes.length; j++) {
if (x[i].childNodes[j].nodeType != 1) continue;
var priceCell = document.createElement("td");
var priceData = document.createTextNode(x[i].childNodes
[j].firstChild==null ? "" : x[i].childNodes[j].firstChild.nodeValue);
priceCell.appendChild(priceData);
row.appendChild(priceCell);
}
tableBody.appendChild(row);
}
document.getElementById("writeroot").appendChild(n ewTable);
}
XML
====================
<products>
<lens>
<uv>
<item>
<en>kenko</en>
<gb>L37</gb>
<description>
</description>
<d49mm>132</d49mm>
<d52mm>143</d52mm>
<d55mm>160</d55mm>
<d58mm>170</d58mm>
<d62mm>210</d62mm>
<d67mm>245</d67mm>
<d72mm>285</d72mm>
<d77mm>320</d77mm>
<d82mm>425</d82mm>
<d86mm>715</d86mm>
</item>
</uv>
</lens>
</products>
Jul 23 '05 #1
1 4776


Stone Chen wrote:
When I try to insert this line of code into my script, Firefox refuses to
render. Could someone explain to me why that is?

if (x[i].firstChild.firstChild.nodeValue==productID) {
some code
}


It is not clear what you are trying to achieve but using childNodes
respectively firstChild and lastChild and expecting a certain kind of
node when you deal with the DOM is prone to errors, DOM implementation
have different ways of dealing with whitespace text nodes in the DOM,
some (Mozilla HTML and XML DOM) include them always, some (IE HTML DOM)
ignore the always, some (MSXML XML DOM) have settings on whether to
ignore them. Thus if you have
<gods>
<god>Kibo</god>
<god>Xibo</god>
</gods>
then with some implementations
xmlDocument.documentElement.firstChild
is a text node with white space, with others it is the <god>Kibo</god>
element node.
Therefore don't navigate firstChild/lastChild/childNodes without
checking the nodeType or better avoid accessing child node if element
nodes are all what you are looking for then use getElementsByTagName or
make sure you walk childNodes node by node until you find the right
nodeType (1 for element nodes, 3 for text nodes).

If you have further problems then try to make a reduced test case and
post a URL but tell us exactly what the Firefox JavaScript console says.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

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

Similar topics

3
by: diablo | last post by:
hi i have a table (leftmenu), the cells of this table has a <A> link in them. <table class="menu_table" width="100%" cellspacing="0" cellpadding="0" id="leftmenu"> <tr> <td><a...
4
by: leodippolito | last post by:
Hello sirs, I am trying to send a POST request to a webservice on the click of a button. This will return me an XML document with a list of combo box items. The problem: in FIREFOX, when the...
6
by: laramie.hartmann | last post by:
I have a script (see below) that accesses a XML file and displays the contents through a series of document.write calls. This all works fine in IE, but not at all in Firefox. I get no errors in the...
4
by: windandwaves | last post by:
Hi Folk Can you please have a look at http://www.friars.co.nz/map.php and let me know if the map is working on IE6 (just do a simple search). Unfortunately, I do not have IE6 anymore and so I...
2
by: hzgt9b | last post by:
I've written a simple javascript page that parses an XML file... (Actually I just modified the "Parsing an XML File" sample from http://www.w3schools.com/dom/dom_parser.asp) The page works great...
3
by: jpk872 | last post by:
I've got an image, when I mouse over it a popup window shows and the person's hobbies are displayed using a CSS popup window. It works in IE, but not Firefox. Any idea why? (lines 23-31) ...
5
by: jpk872 | last post by:
I've got an image, when I mouse over it a popup window shows and the person's hobbies are displayed using a CSS popup window. It works in IE, but not Firefox. Any idea why? (lines 23-31) <img...
13
by: Gretsch | last post by:
Re XML, Javascript, IE, Firefox Hi, I have a very simple & small XML file (only 7 variables). The code works for IE, but not for Firefox. I've search around and found lots of alternatives, but...
8
by: chanshaw | last post by:
Alright this runs just fine in IE but in firefox I get nothing function startup() { if (window.ActiveXObject) { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); }...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.