...

View Full Version : Creating a table, whitespace problem



siferion
04-28-2006, 11:16 PM
Working on this xml stuff farther i encountered a javascript/dom object problem. Have a partial workaround but it's not pretty on the page itself.

The problem is when it encounters a whitespace in an xml file, it doesn't completely write out the "a href" line, it stops at the whitespace in the text. I can get around it by adding a + or %20 to the xml file in place of a space, but then it writes that to the webpage itself as well. I don't mind a symbol being in the link itself, it actually improves the response time of the script being called and accuracy. But it looks ugly on the page to have these + and %20's all over the place.

The code that generates the table:


for(i = 0; i < x.length; i++)
{
var row = document.createElement('TR');
for(j = 0; j < x[i].childNodes.length; j++)
{
if(x[i].childNodes[j].nodeType != 1) continue;
var container = document.createElement('TD');
var theData = document.createTextNode(x[i].childNodes[j].firstChild.nodeValue);
container.appendChild(theData);
if(window.ActiveXObject)
{
if(j == 1)
{
container.innerHTML = '<a href=javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';
}
}
else
{
if(j == 3)
{
container.innerHTML = '<a href=javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';
}
}
row.appendChild(container);
}
tmp.appendChild(row);
}


In the XML file the Item field is the only one giving me issues with whitespace.

The XML file:


<loots>
<loot>
<Player>Some Guy</Player>
<Item>Redemption</Item>
<Date>12-4-06</Date>
<Zone>Wall of Slaughter</Zone>
</loot>
<loot>
<Player>Other Guy</Player>
<Item>Cloth Tunic</Item>
<Date>12-5-06</Date>
<Zone>Greater Faydark</Zone>
</loot>
<loot>
<Player>Dude</Player>
<Item>Rock</Item>
<Date>12-4-07</Date>
<Zone>Freeport</Zone>
</loot>
<loot>
<Player>Some Dude</Player>
<Item>Rock</Item>
<Date>12-4-07</Date>
<Zone>Freeport</Zone>
</loot>
</loots>

dumpfi
04-29-2006, 02:07 AM
Put quotes around your attribute values:
container.innerHTML = '<a href=\'javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")\'>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';dumpfi

Kor
04-29-2006, 08:07 AM
or use DOM allover, and create/append the links instead of using innerHTML

siferion
04-29-2006, 11:37 PM
Put quotes around your attribute values:
container.innerHTML = '<a href=\'javascript:showLoot("' + x[i].childNodes[j].firstChild.nodeValue + '")\'>' + x[i].childNodes[j].firstChild.nodeValue + '<\/a>';dumpfi

Thanks, that worked as intended.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum