View Full Version : .text (.nodeValue) in Firefox?

Lord Kalthorn
05-26-2006, 09:17 PM
I have a successful implementation of picking off XML from a file, currently one that is actually XML but shall be run by PHP in the future. In both Internet Explorer and Firefox (and Opera) it runs correctly and can pick out Attributes from the Nodes quite contentedly. I have had it doing that in all three.

However, attributes are not the most pleasant way to include actual content; and while I have fiddled about with it to put everything I can in attributes I cannot, obviously, for the HTML Content. It is inside CData Tags at the moment. In Internet Explorer, it loads up fine. It even runs the Style Addition and Script Addition functions which then load a stylesheet and/or script for that loaded content to use.

However, in Internet Explorer .nodeValue for said node returns a null. In Firefox and Opera is returns an undefined. In Internet Exploer it works great with .text; but in Firefox and Opera it turns out, again, undefined.

I, despite my distaste for Firefox and Opera, obviously realise that I cannot make my design for my program without it working on at least those two as well as Internet Explorer. But nowhere have I found anything on this subject, all I get is implementations of .nodeValue and even .text that seem to work fine in each Browser.

As a rule I come on here when I have a problem too large for my tiny tiny brain and you always manage to work it out; so I decided I should probably carry that on! The page in question is here.Omega Beta (http://beta.dotomega.com), along with scripts in various places. The actual script I'm talking about is hereomegaPage.js (http://beta.dotomega.com/jscript/omegaPage.js). I should probably post it up in Code Tags, but to be honest its such a complicated mess at the moment I don't imagine that would help at all.

Thanks for your thoughts in advance!

05-26-2006, 09:34 PM
Unfortunatelly, the childNodes are different taken in IE vs Moz (some gaps are ignored by IE) , so that... hm we should probably see your whole code. nodeType coud be a better help detector... or a "gaps cleaner" code... hard to say... show us your code problem, then...

Lord Kalthorn
06-15-2006, 07:07 PM
Kind of got pissed off with Firefox completely and figured I'd get something done in a proper browser before I try and get it working in a hippie browser. Then I forgot completely and did not remember until the guy who's doing the PHP told me it did not work in Firefox :-P Spose I should get it fixed, just still not sure how.

Well suffice to say there is a lot of code :-P The bit that deals with the xml stuff is:

var omegaPage = {
request : function(xmlName) {
if (!omega.checkObjects(xmlName + '.xml')) {
xmlUrl = p.base + '/pages/' + xmlName + '.xml';
xmlUrl += ((xmlUrl.indexOf('?') + 1) ? '&' : '?') + (new Date()).getTime();

if (window.ActiveXObject) {
try {
try {
var xmlRequest = new ActiveXObject('Microsoft.XMLDOM');
} catch(e) {
var xmlRequest = new ActiveXObject('Msxml2.XMLHTTP');

p.xmlRequests[p.xmlRequests.length] = xmlRequest;
p.xmlRequests[p.xmlRequests.length - 1].onreadystatechange = new Function('if (p.xmlRequests[' + (p.xmlRequests.length - 1) + '].readyState == 4 ) {omegaPage.parse(p.xmlRequests[' + (p.xmlRequests.length - 1) + ']); }');
p.xmlRequests[p.xmlRequests.length - 1].load(xmlUrl);

p.objects[p.objects.length - 1] = xmlName + '.xml';
return true;
} catch(e) {}

if (window.XMLHttpRequest) {
p.xmlRequests[p.xmlRequests.length] = new XMLHttpRequest();
p.xmlRequests[p.xmlRequests.length - 1].onreadystatechange = new Function('if (p.xmlRequests[' + (p.xmlRequests.length - 1) + '].readyState == 4 && p.xmlRequests[' + (p.xmlRequests.length - 1) + '].status < 300 ) {omegaPage.parse(p.xmlRequests[' + (p.xmlRequests.length - 1) + '].responseXML); }');
p.xmlRequests[p.xmlRequests.length - 1].open('GET', xmlUrl, true);
p.xmlRequests[p.xmlRequests.length - 1].send(null);

p.objects[p.objects.length - 1] = xmlName + '.xml';
return true;
} else if (omega.checkObjects(xmlName + '.xml')) {
omegaPage.parse(omega.getObjects(xmlName + '.xml'));


parse : function(xmlDoc) {
if (xmlDoc.documentElement && (!xmlDoc.documentElement.tagName || (xmlDoc.documentElement.tagName && xmlDoc.documentElement.tagName.toUpperCase() == 'HTML' ))) {

var pageItem = xmlDoc.getElementsByTagName('pageItem')[0];
if (!pageItem) {

p.info['id'] = pageItem.getAttribute('id');
p.info['page'] = pageItem.getAttribute('page');
p.info['of'] = pageItem.getAttribute('of');
p.info['title'] = pageItem.getAttribute('title');
p.info['desc'] = pageItem.getAttribute('desc');
p.info['lang'] = pageItem.getAttribute('lang');
p.info['base'] = pageItem.getAttribute('base');
p.info['script'] = pageItem.getAttribute('script');
p.info['sheet'] = pageItem.getAttribute('sheet');
p.info['style'] = pageItem.getAttribute('style');
p.info['content'] = xmlDoc.getElementsByTagName('content')[0];


write : function() {
p.page = p.info['id']
document.title = p.info['title'] + ' - ' + p.mainTitle + ' - ' + p.mainDesc
p.language = p.info['lang']
p.url = p.base + p.info['base']
document.getElementById('b').innerHTML += p.info['content'].text;
document.getElementById('hb').innerHTML = '<table id=\'hbt\'><tr><td id=\'hb_breadcrumb\'><a href=\'' + p.info['base'] + '\' onclick=\'return false;\' title=\'' + p.info['desc'] + '\'><span id=\'' + p.language + '_' + p.info['style'] + '\'>' + p.info['title'] + '</span></a><td id=\'hb_permalink\'>' + p.base + p.info['base'] + '</td></td></tr></table>';

if (p.info['script'] != '') {

if (p.info['sheet'] != '') {
if (p.info['style'] == 'default') {
} else {

So its nothing really that complicated at the moment. Because Internet Explorer deals with xml properly :-P The XML I'm playing with is:

<?xml version='1.0' encoding='iso-8859-1' ?>
<?xml-stylesheet type="text/css" href="http://beta.dotomega.com/themes/xml/pages.css"?>
<pageItem id='profile'
title="Lord Kalthorn's Profile"
desc="View Lord Kalthorn's Profile"
the page itself in HTML

To be honest I'd like most of the attributes of pageItem to be in nodes, if I can work out how to do this I will get around to it I'm sure. So yeah, would be great if anybody has any ideas about this! I can't find anything really that works, and this itself just comes out with undefined as shown on http://beta.dotomega.com

Thanks in advance for any help!

06-15-2006, 09:35 PM
Like Kor said, IE strips whitespace nodes, while Firefox doesn't.

So if you have:

<![CDATA[[ blabla ]]>

content.childNodes.length == 2, where the firstChild is the TextNode " " and the lastChild is the CDATA section containing " blabla ". If you are getting undefined, be sure to check that you are working with the node in question.

Furthermore, there is no .text property defined for a CDATA section in DOM2 Core. You may use either .nodeValue or .data to access the content.