Problem adding HTML content loaded using document.load()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • adam@prema.co.nz

    Problem adding HTML content loaded using document.load()

    Hi,

    I'm building a tree control that lazily loads branches of the tree
    using the document.load() method.

    The external XML document that is loaded is generated by a servlet as
    XHTML. What I would like to do is to add the new tree branch to the
    correct place in the document in the browser window using the innerHTML
    property of the parent node.

    The relevant code snippet that I've written to do this is:

    var target = document.getEle mentById(parent Id);
    target.innerHTM L = xmlDoc.document Element.xml;

    This doesn't work, furthermore looking at the W3C DOM API it would seem
    that the document.xml property is a Microsort proprietary extension
    which makes it unsuitable for my application.

    Any pointers on where I'm going wrong are much appreciated.

    Cheers
    Adam

  • Paul R

    #2
    Re: Problem adding HTML content loaded using document.load()

    adam@prema.co.n z wrote:
    <snip>[color=blue]
    > var target = document.getEle mentById(parent Id);
    > target.innerHTM L = xmlDoc.document Element.xml;
    >
    > This doesn't work, furthermore looking at the W3C DOM API it would seem
    > that the document.xml property is a Microsort proprietary extension
    > which makes it unsuitable for my application.[/color]

    Why not

    target.appendCh ild(xmlDoc.docu mentElement.clo neNode(true));

    ?

    Comment

    • Martin Honnen

      #3
      Re: Problem adding HTML content loaded using document.load()



      Paul R wrote:
      [color=blue]
      > adam@prema.co.n z wrote:
      > <snip>
      >[color=green]
      >> var target = document.getEle mentById(parent Id);
      >> target.innerHTM L = xmlDoc.document Element.xml;
      >>
      >> This doesn't work, furthermore looking at the W3C DOM API it would seem
      >> that the document.xml property is a Microsort proprietary extension
      >> which makes it unsuitable for my application.[/color]
      >
      >
      > Why not
      >
      > target.appendCh ild(xmlDoc.docu mentElement.clo neNode(true));[/color]

      That is certainly the right idea in browsers like Mozilla (and its
      derives Netscape 6/7, Firefox) and Opera 7 which have its own DOM
      implementation dealing interoperable with both XML and HTML but then you
      should do it properly and use

      target.appendCh ild(target.owne rDocument.impor tNode(xmlDoc.do cumentElement,
      true));

      but I think the original poster is dealing with IE/Win which uses MSXML
      for XML parsing and XML DOM stuff and unfortuntately there you cannot
      simply move nodes from an MSXML XML DOM document to an IE HTML DOM
      document, you are left with writing your own importNode method which
      tediously creates all nodes/attributes as needed or you can use
      innerHTML to have IE parse markup sent. I think Sarissa
      (<http://sarissa.sourcef orge.net/doc/>), a library trying to provide a
      cross browser API for XML and XSLT stuff, implements importNode for IE
      and in its implementation
      (<http://sarissa.sourcef orge.net/doc/overview-summary-sarissa.js.html >)
      mentions that innerHTML has proven to be much faster for than using DOM
      createXXX methods.

      --

      Martin Honnen

      Comment

      • adam@prema.co.nz

        #4
        Re: Problem adding HTML content loaded using document.load()

        Hi Paul, Martin

        Thanks for clarifying how this works. I'm writing a cross-browser
        script so I'm going to go with Sarissa, it seems to do a nice job of
        hiding the browser-specific APIs.

        Regards,
        Adam

        Comment

        Working...