By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,592 Members | 1,913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,592 IT Pros & Developers. It's quick & easy.

Need HELP: Firefox/nodeValue oddity

P: n/a

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:

<div id="writeroot"></div>
<script type="text/javascript">
importXML("prices.xml", priceTable, "kenko", "L37 Super PRO");
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');
xmlDoc.async = "false";

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

var newTable = document.createElement("table");
var tableBody = document.createElement("tbody");
var row = document.createElement("tr");
var emptyCell = document.createElement("th");
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


for (i=0; i<x.length; i++) {
var row = document.createElement("tr");
// if (x[i].firstChild.firstChild.nodeValue==productID) {
if (window.ActiveXObject) {"cssText", "background-color:
} else if (document.implementation &&
document.implementation.createDocument) {
row.setAttribute("style", "background-color:
// }
var nameCell = document.createElement("th");
var productName = document.createTextNode(x[i].childNodes
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);
document.getElementById("writeroot").appendChild(n ewTable);
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a

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
then with some implementations
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
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.