XML Tutorials

  Home arrow XML Tutorials arrow Page 3 - Handling XML Data for Ajax
XML TUTORIALS

Handling XML Data for Ajax
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2008-01-03

    Table of Contents:
  • Handling XML Data for Ajax
  • Back on the Client: Mining the XML
  • XML Parsing with JavaScript
  • Populating the Form on a Microsoft Browser
  • Populating the Form on Other Browsers

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Handling XML Data for Ajax - XML Parsing with JavaScript


    (Page 3 of 5 )

    Remember, it all starts with our callback() function in JavaScript:

      function callback() {
          if (req.readyState==4) {
              if (req.status == 200) {
                 
    if (window.XMLHttpRequest) {
                     
    nonMSPopulate();
                  }
                  else if (window.ActiveXObject) {
                      
    msPopulate();
                 
    }
             
    }
             
    clear();
          
    }
      }

    Remember howconvertToXML()had to determine whether the browser was Internet Explorer or something else? We have the same problem again here. Whencallback()is invoked, it must check to see whether we are runningActiveXObject(Internet Explorer) orXMLHttpRequest(all other major browsers).

    If the browser is Internet Explorer, we runmsPopulate()to strip out the data from the XML. Otherwise, we runnonMSPopulate(). What's the difference? It has to do with how we get an XML parser and with the API that parser presents to us. Firefox, Mozilla, and Safari all usenew DOMParser()to get a built-in parser that can parse XML, and it's rumored that Opera will support this soon. Internet Explorer, on the other hand, usesnew ActiveXObject("Microsoft.XMLDOM")to get the Microsoft XML parser.

    Although Ajax works on most browsers in their current released states, it's entirely fair to say that the problem of cross-browser compatibility is the Achilles' heel of web applications.

    More XML Tutorials Articles
    More By O'Reilly Media

    blog comments powered by Disqus

    XML TUTORIALS ARTICLES

    - Validation with Document Type Definitions (D...
    - Creating a Well-Formed XML Document
    - Getting to Know XML
    - A Friendly Approach to XML
    - Creating RSS 2.0 Feeds
    - Using Modules in Your RSS Feed
    - RSS 2.0
    - Querying XML: Use Cases
    - Joins and Query Use with XML
    - Solving Problems by Querying XML
    - Performing Set Operations When Querying XML
    - Querying XML
    - Handling Data for Ajax with JSON
    - Handling XML Data for Ajax
    - XML and JSON for Ajax


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap