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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mozilla deals with DOMs differently

    First I am going to say this is not a repost, even though the code is similar to my other posts. My question is slightly different now.

    So the state of my code to load a xml data island into a DOM, after many many iterations is this:
    Code:
    function loadXML(){
    	try {
    		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");	
    		xmlDoc.async = "false"; 
    	 	xmlDoc.onreadystatechange = verify;
    		hasFile = xmlDoc.load(info.XMLDocument);
    		if (hasFile){
    			xmlObj = xmlDoc.documentElement;						// xmlObj is pointing to <test> at this point
    			allTopics = xmlObj.getElementsByTagName("topic");
    		}
    	}
    	catch(e) {
    		xmlObj = document.getElementsByTagName("xml")[0];			// xmlObj is pointing to <test> at this point
    		xmlDoc = (new DOMParser()).parseFromString(xmlObj.innerHTML, 'text/xml');
    		hasFile = true;
    		
    		if (hasFile){
    			allTopics = xmlDoc.getElementsByTagName("topic");
    		}
    	}
    }
    The try is for IE, the catch is for Mozilla, and my xml is something like <xml id="info>...</xml>

    The question i have is if Mozilla can ever have a handle on a DOM the same way that IE does. What happened with me was that i built a page entirely for IE, and then decided I should rebuild the page for cross-platform compliance. I thought that as long as if rebuilt the loadXML() function and had all the right objects from the start, then everything else is the same for both browsers. But I'm finding out that that doesn't seem to be the case.

    For example if I wanted to see what was in my xmlObj, I could write alert(xmlObj.xml) in IE, but in mozilla, I have to do (xmlObj.innerHTML). You would think they are same thing but they aren't. So I guess my question is, am I doing it wrong, or is this just the way DOMs are handled in both situations?

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Location
    underground
    Posts
    186
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #3
    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
    Well, the deal is <xml> is a proprietary tag. Mozilla does not have a specific interface to deal with it, instead it applies a generic HTMLUnknownElement interface to it which only inherits from HTMLElement and doesn't apply anything else. .xml is a property that IE specifies for this particular tag, but since Mozilla doesn't support this tag (nor should it), it doesn't apply any extra properties to it. What you could do is something like:

    Code:
    function HTMLXmlElement() {}
    HTMLXmlElement.prototype.getters = [];
    HTMLXmlElement.prototype.setters = [];
    
    HTMLXmlElement.prototype.getters["xml"] = function() {
        return this.innerHTML;
    };
    // emulate any more necessary properties
    
    
    HTMLUnknownElement.prototype.inheritFrom = function(myInterface) {
    	for (var i in myInterface.prototype) {
    		switch (i) {
    			case "getters":
    				for (var j in myInterface.prototype.getters)
    					this.__defineGetter__(j, myInterface.prototype.getters[j]);
    				break;
    			case "setters":
    				for (var j in myInterface.prototype.setters)
    					this.__defineSetter__(j, myInterface.prototype.setters[j]);
    				break;
    			default:
    				this[i] = myInterface.prototype[i];
    		}
    	}
    }
    And then:

    document.getElementById("myXMLElementID").inheritFrom(HTMLXmlElement);

    and bam, you'll have the .xml property, and whatever else you chose to implement.

  • #4
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'll implement that the next chance I get. But hte question isn't so much as to how the XML is handled as a data island - I don't expect any browser to treat <xml> as anything other than an unrecognizable tag. The real question is whether I can strip the information from the <xml></xml> tags and put it in a usable form such as a DOM object. It seems like IE gives me a really good way of pushing data islands into a DOM, whereas mozilla can parse the <xml></xml> data out, but I can't seem to put it in a similiarly well-formed DOM, not with parseFromString(), not with document.implement.create(). I mean my big issue isn't even with getting the information out of the <xml></xml> it is with this line:

    xmlDoc = (new DOMParser()).parseFromString(xmlObj.innerHTML, 'text/xml');

    It simply doesn't create a DOM like IE's:
    xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async = "false";
    xmlDoc.load(info.XMLDocument);

    meaning xmlDoc in one version is not the same as xmlDoc in the other version when you come out of the tunnel from the other side. I haven't read the cross-browser DOM wrapper article yet. But I'll let you know if it answers my questions. Thanks

  • #5
    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
    What exactly is the DOMParser() returning then? I'd expect only whitespace nodes to be different in the resulting DOM, which you would get anyway with Mozilla, since it preserves them while IE parses them out. But the root element should still be the same, and all the same elements should exist in the DOM hierchy.

  • #6
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well I don't know exactly, I'm trying to read as much as I can, and understand at least half of it. All I know is that at the end of the day if you look at my code above allTopics does not point to the same exact thing because I tried to use it in my code and it works in IE but in Mozilla it doesn't, and the only difference in the paths they take is that IE goes in the try{} statement and Mozilla goes in the catch{} statement. I am still reading that article above which I think is useful, but it will take me a while to digest everything.

  • #7
    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
    Could you perhaps put a working example online somewhere?

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    338
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jkd
    What exactly is the DOMParser() returning then?
    DOMParser.prototype.parseFromString() returns an XMLDocument.

    Happy coding!

  • #9
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the file that I've been working on. Everything should be in the html. The css is in there, the <xml> should be in there. It works in IE (6.0 atleast) but not in mozilla). Hope this is helpful.
    Attached Files Attached Files

  • #10
    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
    Quote Originally Posted by nolachrymose
    DOMParser.prototype.parseFromString() returns an XMLDocument.

    Happy coding!
    I know that... was asking what the document it was returning in this instance looked like. Ah well.

  • #11
    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
    Running your code through a few tests... I don't see any of the issues you're talking about? In Firefox 0.8, xmlDoc is [object XMLDocument], xmlDoc.documentElement is [object Element] with nodeName "test". And getElementsByTagName("topic").length is 4 on each of them.

    I did have to copy/paste some of the script from this thread into the page though, as the Mozilla portion was still trying to load from loader.xml instead of from the embedded XML tag.

  • #12
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So are you saying the script actually worked in FireFox and mozilla because it doesn't work for me (the bottom line). If it worked for you, do you mind sending it to mui_wilson@hotmail.com and let me take a look, with the changes you said you copy and pasted too?

    I mean the lengths might be right, but then accessing allTopics, as I recall, was still not exactly the same between both versions.

  • #13
    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
    Code:
    var xmlDoc;
    var allTopics;
    
    /* creates XML DOM object */
    function loadXML(){
    	if (window.DOMParser)
    	{
    		xmlDoc = (new DOMParser()).parseFromString(document.getElementsByTagName("xml")[0].innerHTML, 'text/xml');
    		hasFile = true;
    	}
    	else if (window.ActiveXObject)
    	{
    		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    		xmlDoc.async = "false";
    		xmlDoc.onreadystatechange = verify;
    		hasFile = xmlDoc.load(info.XMLDocument);
     	}
    	else
    	{
    		alert('Your browser can\'t handle this script');
    		return;
    	}
    
    	
    	if (hasFile) {
    		allTopics = xmlDoc.getElementsByTagName("topic");
    	}
    }
    Last edited by jkd; 06-14-2004 at 08:56 PM.

  • #14
    Regular Coder
    Join Date
    Feb 2004
    Posts
    192
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried that modification to my code, but the javascript as a whole still doesn't work. It works in IE, and what it is suppose to do is, everytime you click on those menus on top, the content is suppose to change on the bottom. It does it in IE, but nothing happens in Mozilla. Except for the error "xmlPoint.getAttribute is not a function"

  • #15
    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
    xmlPoint? Where is that defined...?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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