spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column101


Web Services, Part VI: XML Parsing and Loading from JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

The DOMDocument Graph

When loading an XML file into the browser's memory, the data is organized in an object, the DOMDocument object. The DOMDocument object is an extension of the DHTML DOM object. They share many methods, properties, and events, but the DOMDocument object is much richer in object members. We covered the DOM in Columns 40 through 47. We showed you there how a loaded document is modeled by a graph, with nodes and arcs. Understanding the graph representation of a document is crucial for understanding the DOMDocument's many properties, methods, and events. Be sure to revisit Columns 40 through 47, to get a good basic understanding of the DOM and its graph view.

Converting an XML file to a graph should not be too difficult. Actually, it's more like a tree. The XML tags are the nodes of this tree. Their hierarchical order determines their seats on this tree. Let's look at an example to clarify this point. Here is our mydvd.xml description:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="mydvd.xsl"?>
 <sales>
   <summary>
     <heading>MyDVD Rental Store</heading>
     <subhead>Periodical Sales Report</subhead>
     <description>Sales Report for January, February,
                  and March of 2001</description>
   </summary>
    <data>
     <month>
       <name>January 2001</name>
       <week number="1" dvds_rented="12000" />
       <week number="2" dvds_rented="15000" />
       <week number="3" dvds_rented="18000" />
       <week number="4" dvds_rented="11800" />		  
     </month>
     <month>
       <name>February 2001</name>
       <week number="1" dvds_rented="11500" />
       <week number="2" dvds_rented="12390" />
       <week number="3" dvds_rented="19050" />
       <week number="4" dvds_rented="11200" />		  
     </month>
     <month>
       <name>March 2001</name>
       <week number="1" dvds_rented="15300" />
       <week number="2" dvds_rented="12390" />
       <week number="3" dvds_rented="10050" />
       <week number="4" dvds_rented="11230" />		  
     </month>
   </data>
 </sales>

Here is the tree representation of this document:

Next: How to read an XML file

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: January 14, 2002
Revised: January 14, 2002

URL: http://www.webreference.com/js/column101/2.html