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 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    retrieving HTML from responseXML

    I get back an xml doc which contains HTML info that I want to retrieve with all of its tags. But my "content" gets a null value. If content doesn't contain html tags then it works fine.

    Here is the code:
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
    var xmlDoc=xmlHttp.responseXML.documentElement;
    document.getElementById("title").value=
    xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
    document.getElementById("subtitle").value=
    xmlDoc.getElementsByTagName("subtitle")[0].childNodes[0].nodeValue;

    // update content editor
    var editor = FCKeditorAPI.GetInstance('myFCKeditor');
    var content = xmlDoc.getElementsByTagName("content")[0].childNodes[0].nodeValue;
    editor.SetHTML(content);
    }

    Here is the xml:
    <page>
    <title>About the Mishna program</title>
    <subtitle>Mishna program</subtitle>

    <content>
    <p>
    The Mishna Program is a must for anyone serious in developing a strong bekius in mishnaios which is critical to learning gemara.
    </p>
    </content>
    </page>

    Thanks for any help.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    since you are extracting the contents of the xml document the the nodeValue of any element node (in your case content) is always null. what you should be doing is serializing the contents of the content tag to a string

    Code:
    function xmlContent(xmlNode) {
      if ( window.XMLSerializer ) {
       // FF
        return new XMLSerializer().serializeToString(xmlNode);
      }
      // IE
      return xmlNode.xml;
    }
    ...
    
    var content = xmlDoc.getElementsByTagName("content")[0];
    editor.SetHTML(xmlContent(content ));
    Last edited by shyam; 09-14-2008 at 05:14 PM. Reason: typo
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • Users who have thanked shyam for this post:

    fruminovator (09-14-2008)

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks. I'll try that.

  • #4
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    It crashes on this line (using FF):

    return new XMLSerializer().serializerToString(xmlNode);

    What am I missing?

  • #5
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Also
    It crashes on this line (using FF):

    return (new XMLSerializer()).serializerToString(xmlNode);

    What am I missing?

  • #6
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by fruminovator View Post
    Also
    It crashes on this line (using FF):

    return (new XMLSerializer()).serializerToString(xmlNode);

    What am I missing?
    sorry my bad ...typo

    Code:
    return (new XMLSerializer()).serializeToString(xmlNode);
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #7
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    yeah, I figured that out.
    thanks.

    It works now!


  •  

    Posting Permissions

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