Results 1 to 6 of 6

Thread: appendChild implementation doesn't work with w3schools's loadXMLString function

  1. #1
    Join Date
    Oct 2007
    Location
    Germany, Berlin
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default appendChild implementation doesn't work with w3schools's loadXMLString function

    Heyho,

    I have a problem: I made a window handler class. It is great and I am very proud of it but there is the problem that it now runs the document.write function although I'd like to run it in a spontaneous call in the context and not every time at the end of the document. I tried to use that loadXMLString function of the w3c but it doesn't work.
    Here's a short example:
    Code:
    function VirtualWindows() {
    
    this.putContent = function(windowcontent) {
       var content = this.loadXMLString(windowcontent);
       var mainbody = document.getElementsByTagName("body")[0];
       mainbody.appendChild(content.documentElement);
    };
    
    this.loadXMLString = function(txt) {
    	try { //Internet Explorer
    		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    		xmlDoc.async = "false";
    		xmlDoc.loadXML(txt);
    		return(xmlDoc); 
    	}
    	catch(e) {
    		try { //Firefox, Mozilla, Opera, etc.
    			parser = new DOMParser();
    			xmlDoc = parser.parseFromString(txt,"text/xml");
    			return(xmlDoc);
    		}
    		catch(e) { alert(e.message); }
    	}
    	return(null);
    };
    }
    call:
    Code:
    var windowmanager = new VirtualWindows();
    windowmanager.putContent('<div class="testmessage">hey, I am a test. What do you are? <div><span>I am a child element that only has one parent</span></div><div></div></div>');
    Why doesn't this work? If I try alert(content.documentElement.nodeName); at the end of the putContent() function "div" appears but I cannot get the class, there is no possibility to implement it in the document and nothing else works.

    Please, help!!!

    greetings
    Max
    Last edited by ReMaX; 04-25-2008 at 01:23 AM. Reason: äh, one more mistake

  2. #2
    Join Date
    Oct 2007
    Location
    Germany, Berlin
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Nobody knows an answer? Help!!!
    *push*

  3. #3
    Join Date
    Dec 2007
    Location
    Ankara, Turkey
    Posts
    160
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    Your "putContent" function receives only the content but you are giving "testWindow" as the first parameter and the content as the second parameter.

    Why do you do that?

  4. #4
    Join Date
    Oct 2007
    Location
    Germany, Berlin
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    ah, excuse me. That should only be an abstraction. I already changed the code afterwards but I forgot to turn the call to a function with one parameter . Anyway, it doesn't work! Waaaaah

    greetings
    Max
    Last edited by ReMaX; 04-25-2008 at 01:26 AM. Reason: bah, that spelling errors in the evening^^

  5. #5
    Join Date
    Dec 2007
    Location
    Ankara, Turkey
    Posts
    160
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default

    Hey, It works with the proper call
    I mean, it added the div to the bottom of my page when I tried it

  6. #6
    Join Date
    Oct 2007
    Location
    Germany, Berlin
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hm, okay, so everything is fine. I think I simply was too tired that morning. Now I made it with element.innerHTML. A few days ago I thought that would be the same as element.data (the first TextNode) but now I know it contains the "innerHTML", all childElements. That's how it works, too!
    Excuse me for wasting your time.

    greetings
    Max

Bookmarks

Posting Permissions

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