XML
  Home arrow XML arrow Page 5 - Introduction to XML Document Object Model
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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

Introduction to XML Document Object Model
By: Gayathri Gokul
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2004-02-09

    Table of Contents:
  • Introduction to XML Document Object Model
  • Covering Our Base
  • DOM Simplified
  • Working With XML Data
  • Traversing the Nodes in an XML Document

  • 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


    Introduction to XML Document Object Model - Traversing the Nodes in an XML Document


    (Page 5 of 5 )



    Parse XML


    <FONT face="Verdana, Arial, Helvetica, sans-serif">#document Type:DOCUMENT(9)   Value=null
    BookAuthors  Type:ELEMENT(1)  Value:null
    Author  Type:ELEMENT(1)  Value:null
    au_id  Type:ELEMENT(1)  Value:null</FONT><FONT face="Verdana, Arial, Helvetica, sans-serif">
    <class=MsoBodyText2 style="MARGIN: 0in 0in 0pt">
    #text  Type Text(3)  Value:1001
    au_lname Type:ELEMENT(1)  Value:null
    <class=MsoBodyText2 style="MARGIN: 0in 0in 0pt">
    #text  Type Text(3)  Value:Gates
    au_fname  Type:ELEMENT(1)  Value:null
    <class=MsoBodyText2 style="MARGIN: 0in 0in 0pt"
    <
    class=MsoBodyText2 style="MARGIN: 0in 0in 0pt">#text  Type Text(3)  Value: Bill
    Author  Type:ELEMENT(1)  Value:null
    au_id  Type:ELEMENT(1)  Value:null

    <class=MsoBodyText2 style="MARGIN: 0in 0in 0pt">#text  Type Text(3)  Value:1002
    au_lname Type:ELEMENT(1)  Value:null

    <class=MsoBodyText2 style="MARGIN: 0in 0in 0pt">#text  Type Text(3)  Value:Potter
    au_fname  Type:ELEMENT(1)  Value:null

    <class=MsoBodyText2 style="MARGIN: 0in 0in 0pt">#text  Type Text(3)  Value: Harry

     

    Hope you got a clear and quick picture of the recursive nature of the XML DOM. At the top we have the #document Type node, which is an inherent parent, that means the root node of all XML documents. Pay careful attention though.  It’s not actually an element-it has a type of DOCUMENT. So the root of the XML data is an XML document, but under that you have XML Elements.

     

    In our case the first root element is the BookAuthors element. This in turn contains an element for each Author and an element for each property of the Author. We also notice some additional information for each leaf node (i.e. node with no children).  We have another node called #text. This actually contains the text of the node. You may ask then why does each element have a value of null and its sub-element called #text contains the value of the node. The answer is very simple.  Some nodes may have both, another node, as well as contain text. If a node contains both text and other nodes, what will be the value?  Will it be a text or the child node? This led W3C to specify that text for a node be always held in a child node of type Text.

     

    So this leaves us with the final part of the code, for when we accessed the node we did not step deep down to another level in the tree to access the child. We will do it now! 

     

    </SPAN><?xml:namespace prefix /><o:p> </o:p></FONT>
    <
    class=MsoNormal style="MARGIN: 0in 0in 0pt; TEXT-ALIGN: justify"><SPAN style="FONT-SIZE: 11pt; mso-bidi-font-size: 10.0pt"><STRONG><FONT size=2><FONT face="Verdana, Arial, Helvetica, sans-serif"></b>   Value: <b>’ baNode.nodeValue </b><br>;<o:p></o:p></FONT></FONT></STRONG></SPAN>
    <
    class=MsoBodyText2 style="MARGIN: 0in 0in 0pt"><FONT face="Verdana, Arial, Helvetica, sans-serif">

     

    Voila!  We have used the nodeValue property, too. This is Microsoft’s simplified extension of DOM. W3C specified that to access the value of the node-you have to traverse to the child to access the associated TEXT node. Microsoft felt that such a common action as accessing the value of a node to get at the text it holds must be simplified, hence intelligently delegated it by introducing nodeValue property to handle the TEXT nodes.

     

    This tutorial has shown you about DOM and how it stores XML data in a tree structure. Now that you understand how XML works and have been introduced to DOM, next we can take a look at how XML integrates with ADO.


    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.

     

    XML ARTICLES

    - More on Triggers and Styles and Control Temp...
    - Looking at Triggers with Styles and Control ...
    - A Closer Look at Styles and Control Templates
    - Styles and Control Templates
    - Properties and More in XAML
    - Elements and Attributes in XAML
    - XAML in a Nutshell
    - Importing XML Files into Access 2007
    - Using MSXML3.0 with VB 6.0
    - MSXML, concluded
    - MSXML, continued
    - MSXML Tutorial
    - Generating XML Schema Dynamically Using VB.N...
    - XSL Transformations using ASP.NET
    - Applying XSLT to XML Using ASP.NET





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT