Problem adding HTML content loaded using document.load()

A

adam

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.getElementById(parentId);
target.innerHTML = xmlDoc.documentElement.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
 
M

Martin Honnen

Paul said:
Why not

target.appendChild(xmlDoc.documentElement.cloneNode(true));

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.appendChild(target.ownerDocument.importNode(xmlDoc.documentElement,
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.sourceforge.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.sourceforge.net/doc/overview-summary-sarissa.js.html>)
mentions that innerHTML has proven to be much faster for than using DOM
createXXX methods.
 
A

adam

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top