XML Tutorials
  Home arrow XML Tutorials arrow Page 5 - Handling XML Data for Ajax
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
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 / 1
    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

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Handling XML Data for Ajax - Populating the Form on Other Browsers


    (Page 5 of 5 )

    The code for handling non-Microsoft browsers, shown in Example 4-7, is similar; there are some minor differences in the parser API, but that's about it.

    Example 4-7. The nonMSPopulate( ) function

     1 function nonMSPopulate() {
     2     var resp = req.responseText;
     3     var parser = new DOMParser();
     4     var dom = parser.parseFromString(resp,"text/xml");
     5
     6     decVal = dom.getElementsByTagName("decimal");
     7     var decimal = document.getElementById('decimal');
     8     decimal.value=decVal[0].childNodes[0].nodeValue;
     9
    10     hexVal = dom.getElementsByTagName("hexadecimal");
    11     var hexadecimal = document.getElementById('hexadecimal');
    12     hexadecimal.value=hexVal[0].childNodes[0].nodeValue;
    13
    14     octVal = dom.getElementsByTagName("octal");
    15     var octal = document.getElementById('octal');
    16     octal.value=octVal[0].childNodes[0].nodeValue;
    17
    18     hyperVal = dom.getElementsByTagName("hyper");
    19     var hyper = document.getElementById('hyper');
    20     hyper.value=hyperVal[0].childNodes[0].nodeValue;
    21
    22     binaryVal = dom.getElementsByTagName("binary");
    23     var bin = document.getElementById('bin');
    24     bin.value=binaryVal[0].childNodes[0].nodeValue;
    25 }

    We create a newDOMParser(line 3), then we create a DOM on line 4 from the XML string that we received from the servlet. Next, we get the element between the<decimal></decimal>tags (line 6) by callingdom.getElementByTagName("decimal"). After retrieving thedecimalform element from our HTML document, we retrieve the value sent to us in the XML and use it to set the appropriate field:

      decimal.value=decVal[0].childNodes[0].nodeValue;

    The reference todecVal[0]gets the data between the<decimal></decimal>tags. If we had two sets of<decimal></decimal>tags, we would reference the second set asdecVal[1].

    This is what the data should look like in the response sent from the servlet:

      <converted-values>
          <decimal>97</decimal>
          <hexadecimal>0x61</hexadecimal>
          <octal>0141</octal>
          <hyper>&amp;0x61;</hyper>
          <binary>1100001B</binary>
      </converted-values>

    Please check back next week for the conclusion to this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Ajax on Java," published by O'Reilly. We...
     

    Buy this book now. This article is excerpted from chapter four of the book Ajax on Java, written by Steven Douglas Olson (O'Reilly, 2007; ISBN: 0596101872). Check it out today at your favorite bookstore. Buy this book now.

    XML TUTORIALS ARTICLES

    - 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-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT