473,881 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3370


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.append Child(
someNode.ownerD ocument.importN ode(
nodeFromSecondD ocument,
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.create Element
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.create Element
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.create Element 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.append Child(
someNode.ownerD ocument.importN ode(
nodeFromSecondD ocument,
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.create Element
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.create Element
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.create Element 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.create Element 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.create Element() 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.create Element 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.create Element() 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:
Interestingl y the author of Sarissa (Manos Batsis) found that using
document.cre ateElement 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.create Element() 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.hasAttribu tes() (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.hasAttribu tes() (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
1898
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 happening with this script ----------------------------------------------------- xmlhttp = new XMLHttpRequest();
42
34269
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 1.07/Linux, Firefox 1.5/Linux, Firefox 1.5/Windows and Firefox 1.5/Mac, Safari/Mac. It works perfectly on a lot of configurations but, on some PC with Firefox 1.5/Windows (not all), the Javascript code with XmlHttpRequest
6
7306
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 readyState is always set to 1 (loading). Ive tried using the same XMLHTTPRequest object, and making a 2nd XMLHTTPRequest object with the same results. Heres my code thats giving me problems... function RefreshChat() {
1
4040
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 technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
1
5314
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? Here's my code: The function mySaveFunction() is called by clicking the "Update" button, after the user changes the data which is populated in the form fields, which was retrieved via XMLHttpRequest from an XML external file. I know that...
2
2110
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 but for other browser like-firefox,opera its not working......... i m giving u my complete xml,xsl and transformation code....u only paste and check why it is not working for other browser.....and correct it and let me know......this is really a big...
2
2455
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 session echo "success"; ?>
3
2147
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 web-page url and create a resource box or credit line that is added to the selected text when the data is pasted. You will see that the meta keywords are used (randomly) as the anchor text
0
9926
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9776
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10716
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10812
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10399
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7952
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7108
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5780
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.