• Add a Comment
  • Edit
  • More Actions v
  • Quarantine this Entry

Comments (3)

1 localhost commented Permalink

Or... you could use one of the upteen million Ajax frameworks to that take care of this goo for you.I've been using dojo recently with much success. Here's some code to make an Ajax request that successfully returns an XML document, regardless of browser:

<script type="text/javascript" src="dojo.js"></script>dojo.require("dojo.io.*");var ajaxArgs= {    url: "/some/ajax/url",    mimetype: "application/xml",  // let's be NLS-friendly    load: function(type, xmlData, evt) {       myCallbackFunction(xmlData);    }};dojo.io.bind(ajaxArgs);function myCallbackFunction(xmlData) {    var topLevelElement=        xmlData.getElementsByTagName("topLevelElement");    // etc.}

2 localhost commented Permalink

FYI, I went ahead and wrote a short intro blog on Dojo, in case you or any of your readers are not familiar with it and would like to learn more.

3 localhost commented Permalink

I had forgotten to comment on this, but Bill's blog post today reminded me :-)In the typical case, you never actually parse XML in JS like this. You are either getting XML back from an XmlHttpRequest call, in which case it provides you a DOM for the XML, or you can make use of the "innerHTML" property of existing HTML DOM elements to do this for you. If you just want to insert a wad of HTML (or XML), just do something like: thatElement.innerHTML = "literal XML data here"If you want to get it parsed for you, you can do that line above, then traverse the DOM for the wad you just inserted programmatically. If this is transient data, you can add a hidden DIV (hidden by styling it to not be visible), and do your wad insertion there. A little hacky, but doesn't require browser checks, since all the browsers support the non-spec'd innerHTML bizness.

Add a Comment Add a Comment