XML
  Home arrow XML arrow Page 5 - XML Responses and AJAX
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
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

XML Responses and AJAX
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 25
    2006-02-27

    Table of Contents:
  • XML Responses and AJAX
  • A brief explanation of innerHTML
  • AJAX returning an XML document
  • A Quick look at XMLDOM
  • Student Nodes Collection

  • 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


    XML Responses and AJAX - Student Nodes Collection


    (Page 5 of 5 )

    We can get a reference to the student nodes using the getElementsByTagName method. From this we can find the number of such student nodes. Once we know how many there are (nodes.length), we can iterate through the collection and find the individuals as shown in the following code snippet.

    var nodes=xhr.responseXML.getElementsByTagName("student");
                  document.getElementById(9).innerHTML=nodes.length;
            for (i=0; i<nodes.length ;="" i="" {="" document.getelementbyid(10+i).innerhtml="nodes.item(i).text;" }=""></nodes.length>

    Displayed result for the above snippet

    4 Linda Jones Access, VB5.0
    Adam Davidson Cobol, MainFrame
    Charles Boyer HTML, Photoshop
    Charles Mann Cobol, MainFrame

    Relevant portion of the XML Document

    Trapping error in XML document

    Using the XMLDOM's parseError property the errant line in the XML document can be found and corrected. The code needed for this will be:

    err = xhr.responseXML.parseError;
    if (err.errorCode != 0)
    alert("Error on line " + err.line + "\n" + err.srcText);

    You may test it by making a malformed XML document by replacing the following line in the XML file WebClass.xml

     <legacySkill>Cobol, MainFrame</legacySkill>

    with

    <legacySkill>Cobol, MainFrame</legacySkiLl>

    and the above code if placed in the source code will produce this prompt,
    error information.


    Summary

    This tutorial looks at responseXML's parsing via XMLDOM properties and methods. The XML document must be well formed. Malformed XML documents retrieved using the above code will produce an error. However, if you are returning the responseText, the code still works. It is during XMLDOM parsing that the error is detected. You can verity this by trying to return responseText for a malformed XML Document. Again, JavaScript must be enabled and the script is case sensitive. This tutorial has only implemented the code for IE.


    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.

       · There was some good information in that article but I had to "view source" to see...
       · I saw some errors and tried to fix them. If you're still seeing problems, please...
       · Hi, thank you for pointing this out to us.I found one line on the last page that...
       · Appears like there was some problem with on of the pages and seems to have been...
       · I've tried taking the xml example and the code example, placing them on my server...
     

    XML ARTICLES

    - Using Regions with XSL Formatting Objects
    - Using XSL Formatting Objects
    - More Schematron Features
    - Schematron Patterns and Validation
    - Using Schematron
    - Datatypes and More in RELAX NG
    - Providing Options in RELAX NG
    - An Introduction to RELAX NG
    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek