What is XML?
* XML stands for EXtensible Markup Language
* XML is a markup language much like HTML
* XML was designed to carry data, not to display data
* XML tags are not predefined. You must define your own tags
* XML is designed to be self-descriptive
* XML is a W3C Recommendation
There are several ways to import XML. None of them are truly cross browser, so a combination must be used. The two main techniques have a normal constructor for standards based browsers, and an ActiveX version for Internet Explorer. The syntax used to load the document is the same in both versions, and the functionality is comparable.
* XML DOM Creates an XML document object, then makes it load an XML file. It uses either the createDocument method of the document.implementation object (followed by a call to load()), or the Microsoft.XMLDOM ActiveX object.
* XMLHttpRequest creates an HTTP request using GET or POST and uses it to load an XML file. It uses the XMLHttpRequest contructor, or the Microsoft.XMLHTTP ActiveX object.
* The iframe technique loads an XML page in an iframe then parses it as a document.
These techniques are equivalent for most purposes, except that the second can pass POST information in the request, allowing for more than 4KB of encoded data to be sent to the server (either can pass GET information in the requested URL string). Since the iframe technique cannot use POST without creating history entries, I restrict myself to GET in all situations. The second technique does offer superior error handling (in case the XML file does not load), and can handle synchronous/asynchronous loading better.
As well as that, the second technique is being included in the upcoming W3C specification, and is the basis of most AJAX (the annoying buzzword, not the bathroom cleaner) applications. It offers an extra advantage that it can deal with plain text files, and raw source code instead of just providing a DOM interface.
PPK's example uses only the first technique.
Newer versions of ICEbrowser also support their own version of XMLHttpRequest created using window.createRequest() or new XMLHttpRequest() but they do not provide a responseXML DOM, and are useless here. It would be possible to cludge this script to force ICEbrowser to use the iframe like it used to, but the DOM of the iframe page also seems to be broken. So it is better to just wait until it supports XMLHttpRequest properly.
Note: If you want to submit form data to construct the XML data URL, I have demonstrated how in a previous email.
I could just use XMLHttpRequest and one of the ActiveX techniques, which would extend support to a few more browsers, as well as making the script a lot easier, since repeated 'if' tests are not required, and no browsers produce errors. However, I am not satisfied with just that. What I do is I start the same way as PPK, but using XMLHttpRequest instead of document.implementation. Failing that, I try new ActiveXObject('Microsoft.XMLHT TP') with a check to prevent problems with ICEbrowser then fall back to new ActiveXObject('Microsoft.XMLDO M') if XMLHTTP is not available (either ActiveX method could be used, but the latter is perhaps a little easier and will also work with file:// URLs, but has broken implementations on many installs). I also use try-catch to prevent IE 5 Mac from failing when it tries to use its crippled ActiveXObject. I did try the same for ICEbrowser, but apparently it fails to use try-catch properly for this sort of situation.
At this stage, I have done almost the same as PPK, apart from my error avoiding. However (and here is the critical part), what I do next is I check if both of those techniques failed and if they did, I create a hidden iframe, and load the XML document into it. Normally, I would use onload, but I found that only Opera 7.5+ uses it here, despite the fact that IE 5 Mac and ICEbrowser also use t
Answered by
shaista
, an ibibo Master,
at
5:31 PM on May 07, 2008