Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    .text (.nodeValue) in Firefox?

    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, along with scripts in various places. The actual script I'm talking about is hereomegaPage.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!

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    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'));
    		}
    
    		return;
    	},
    
    	parse : function(xmlDoc) {
    		if (xmlDoc.documentElement && (!xmlDoc.documentElement.tagName || (xmlDoc.documentElement.tagName && xmlDoc.documentElement.tagName.toUpperCase() == 'HTML' ))) {
    			return;
    		}
    
    		var pageItem = xmlDoc.getElementsByTagName('pageItem')[0];
    		if (!pageItem) {
    			return;
    		}
    
    		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];
    		
    		omegaPage.write();
    	},
    
    	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'] != '') {
    			omega.addScripts(p.info['script']);
    		}
    
    		if (p.info['sheet'] != '') {
    			omega.addSheets(p.info['sheet']);
    			if (p.info['style'] == 'default') {
    				omega.changeStyle('ocean');
    			} else {
    				omega.changeStyle(p.info['style']);
    			}
    		}
    	}
    };
    So its nothing really that complicated at the moment. Because Internet Explorer deals with xml properly :-P The XML I'm playing with is:

    Code:
    <?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'
    			page='1'
    			of='1'
    			title="Lord Kalthorn's Profile"
    			desc="View Lord Kalthorn's Profile"
    			lang='en-gb'
    			base='/profile'
    			script='omegaProfile'
    			sheet='profile'
    			style='default'>
      <content>
        <![CDATA[
    	the page itself in HTML
        ]]>
      </content>
    </pageItem>
    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!

  • #4
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Like Kor said, IE strips whitespace nodes, while Firefox doesn't.

    So if you have:
    Code:
    <content>
        <![CDATA[[ blabla ]]>
    </content>
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •