473,385 Members | 1,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 3335


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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.