472,374 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 software developers and data experts.

Adding XML from an XMLHttpRequest to current document in IE

Is there a way to do this in IE?

In Firefox, one can simply append a node from an XML return to the
current document. IE whinges about 'No such interface supported'

--
Ian Collins.
Feb 1 '06 #1
8 3270


Ian Collins wrote:
Is there a way to do this in IE?

In Firefox, one can simply append a node from an XML return to the
current document. IE whinges about 'No such interface supported'


Note that according to the W3C DOM you should not simply move nodes from
one document to the other but rather use importNode e.g.
someNode.appendChild(
someNode.ownerDocument.importNode(
nodeFromSecondDocument,
true
)
)
Mozilla allows you to get away without using importNode but Opera
requires that and is closer to the W3C specification that way.

As for IE, no, the XML DOM in IE is not implemented by IE itself but
rather the COM component MSXML and you can't move or import nodes
between the HTML DOM that IE (or internally MSHTML) implements and the
XML DOM that MSXML implements.

You would have to write your own importNode that walks the XML DOM tree
and then recreates nodes in the HTML DOM using document.createElement
and other node creating methods.

Or you let the HTML parser of IE do its work by feeding responseText to
innerHTML of an HTML element for instance.


--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 1 '06 #2
Martin Honnen wrote:

You would have to write your own importNode that walks the XML DOM tree
and then recreates nodes in the HTML DOM using document.createElement
and other node creating methods.

Or you let the HTML parser of IE do its work by feeding responseText to
innerHTML of an HTML element for instance.


Or use Sarissa which already has a working implementation of importNode for
IE.

Interestingly the author of Sarissa (Manos Batsis) found that using
document.createElement was much slower than using innerHTML, so he
serializes the XML DOM node and feeds that to innerHTML.
Feb 1 '06 #3
Martin Honnen wrote:


Ian Collins wrote:
Is there a way to do this in IE?

In Firefox, one can simply append a node from an XML return to the
current document. IE whinges about 'No such interface supported'

Note that according to the W3C DOM you should not simply move nodes from
one document to the other but rather use importNode e.g.
someNode.appendChild(
someNode.ownerDocument.importNode(
nodeFromSecondDocument,
true
)
)
Mozilla allows you to get away without using importNode but Opera
requires that and is closer to the W3C specification that way.

Thanks, I hadn't looked at the Opera implementation. I had tried
importNode with FF and found it to work.
As for IE, no, the XML DOM in IE is not implemented by IE itself but
rather the COM component MSXML and you can't move or import nodes
between the HTML DOM that IE (or internally MSHTML) implements and the
XML DOM that MSXML implements.
Yuck, what a waste. Kind of makes XML data redundant.
You would have to write your own importNode that walks the XML DOM tree
and then recreates nodes in the HTML DOM using document.createElement
and other node creating methods.
I'd been doing this when realised what a waste of time it was.
Or you let the HTML parser of IE do its work by feeding responseText to
innerHTML of an HTML element for instance.

I think I'll stick with JSON.
--
Ian Collins.
Feb 1 '06 #4
Duncan Booth wrote:
Martin Honnen wrote:

You would have to write your own importNode that walks the XML DOM tree
and then recreates nodes in the HTML DOM using document.createElement
and other node creating methods.

Or you let the HTML parser of IE do its work by feeding responseText to
innerHTML of an HTML element for instance.

Or use Sarissa which already has a working implementation of importNode for
IE.

Interestingly the author of Sarissa (Manos Batsis) found that using
document.createElement was much slower than using innerHTML, so he
serializes the XML DOM node and feeds that to innerHTML.


Thanks Duncan, I'll look at that.

I wonder how performance compares with JSON, or simply receiving the XML
as text to avoid the serialisation.

--
Ian Collins.
Feb 1 '06 #5
Duncan Booth wrote:
Interestingly the author of Sarissa (Manos Batsis) found that using
document.createElement was much slower than using innerHTML, so he
serializes the XML DOM node and feeds that to innerHTML.


I can see why, if you call document.createElement() in IE, the resulting
element has 79 attributes with a value of 'null'. Must be creating an
attribute node for each of these...

--
Ian Collins.
Feb 1 '06 #6
Ian Collins wrote:
Duncan Booth wrote:
Interestingly the author of Sarissa (Manos Batsis) found that using
document.createElement was much slower than using innerHTML, so he
serializes the XML DOM node and feeds that to innerHTML.


I can see why, if you call document.createElement() in IE, the resulting
element has 79 attributes with a value of 'null'. Must be creating an
attribute node for each of these...

Not quite. When you create an element in IE it doesn't create all those
empty attributes until you access the 'attributes' collection. If you stick
to getAttribute/setAttribute and avoid accessing 'attributes' you can get
big performance improvements.

Kupu used to do content filtering by iterating over the attributes
collection on each node when you saved, and only keeping those attributes
which weren't banned and were non-null. I changed it to have a whitelist of
valid attributes for each tagname, and testing each of those attributes for
existence using getAttribute(). I expected a speedup of maybe 10-fold since
the whitelist meant it was only processing about 10th as many attributes,
but in fact it was closer to 100 times faster, I think because IE was no
longer creating the attributes object at all.

What I think it does show is that although IE exposes a DOM interface,
internally it does everything with totally different data structures. There
are plenty of other indications of this: create an HTML page with a <base>
tag followed by the <body> tag, then have a look at the base element's
firstChild and nextSibling: they will both be the body element.

Another fun one is the sequence <font><p>text</font></p>: the <p> element
is both firstChild and nextSibling of the <font> element. You might not
think it matters (after all the HTML was invalid in the first place), but
if you paste into a contentEditable area some text copied from Microsoft
Works (or some other MS applications), the rich text on the clipboard gets
converted to exactly that 'HTML' by IE, so an editor based on
contentEditable has to be able to handle (and ideally clean-up) such
situations.

Both of these indicate that the internal structure used by IE is pretty
close to the unparsed HTML and the DOM nodes are simply providing a view
onto the much less structured HTML.
Feb 2 '06 #7
Duncan Booth wrote:
Ian Collins wrote:

Duncan Booth wrote:
Interestingly the author of Sarissa (Manos Batsis) found that using
document.createElement was much slower than using innerHTML, so he
serializes the XML DOM node and feeds that to innerHTML.


I can see why, if you call document.createElement() in IE, the resulting
element has 79 attributes with a value of 'null'. Must be creating an
attribute node for each of these...


Not quite. When you create an element in IE it doesn't create all those
empty attributes until you access the 'attributes' collection. If you stick
to getAttribute/setAttribute and avoid accessing 'attributes' you can get
big performance improvements.

I see, I was using node.attributes.length rather than
node.hasAttributes() (missing in IE?), so I guess I was making a rod for
my own back. Kind of hard to tell if an element has attributes without
invoking this behaviour though.

--
Ian Collins.
Feb 2 '06 #8
Ian Collins wrote:
Duncan Booth wrote:
Not quite. When you create an element in IE it doesn't create all
those empty attributes until you access the 'attributes' collection.
If you stick to getAttribute/setAttribute and avoid accessing
'attributes' you can get big performance improvements.

I see, I was using node.attributes.length rather than
node.hasAttributes() (missing in IE?), so I guess I was making a rod
for my own back. Kind of hard to tell if an element has attributes
without invoking this behaviour though.

If you know what attributes you expect you can call getAttribute and
skip the ones which are null or the default value for the attribute, but if
you've been setting attributes with arbitrary and unknown names there is
nothing for it but to use the attributes collection and take the penalty.

I'm pretty sure that once you've access the attributes collection on a node
once it doesn't recreate it for subsequent accesses, so this only really
bites if you need to iterate through the entire DOM.

Feb 2 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: SE | last post by:
Hi all, Apologies if this has been done before. I am trying to do some stuff with XMLHttpRequest in mozilla but no dice. I have finally pared everything down to the minimum to see what is...
42
by: Greg | last post by:
Hi, I've designed a bookmark in Ajax / PHP that I will put soon on sourceforge.net. But I've got an very tricky bug. I try it on some computers with Internet Explorer/Windows, Firefox...
6
by: Nathan | last post by:
Can I run two XMLHTTPRequest objects at the same time? Im able to get one to work without problems. If I put a call to a function inside the first ones onreadystatechange function, the 2nd ones...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
1
by: Tarik Monem | last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest. Can I use PHP do what I'm trying to do?...
2
by: abhimanyu singh | last post by:
i m facing a serious probs now a days............ its seems easy but for me i found it difficult......... i want to do transformation usig xsl and xml(adding parameter). for IE its working fine...
2
by: gradinafrica | last post by:
I'm trying to create a log out button that uses AJAX to call a php file which ends the current session: //logout.php <?php if (!session_start()); session_destroy(); //Destroys the...
3
by: jeddiki | last post by:
Hi, I am using this script which is nearly working correctly, but not quite! When a user selects some text from the web-page and copies it, the script is supposed to pick up the current...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.