spacer
Yehuda Shiran March 3, 2002
Assigning Node Numbers to Non-Data Tags
Tips: March 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Each XML tag is a DOMDocument node. Some tags define the default values for the current XML file. Do not overlook these tags -- they all take up node numbers and thus affect the DOMDocument mapping into nodes. Even the referenced DTD file takes up some node numbers.

Let's look at the top-tier nodes of mydvd7.xml. The root has four child nodes. The first one is xml (xmlDoc.childNodes[0].nodeName):

  <?xml version="1.0"?>
The second child node is xml-stylesheet (xmlDoc.childNodes[1].nodeName):

  <?xml-stylesheet type="text/xsl" href="mydvd7.xsl"?>
The third child is the DTD (Document Type Definition) file. The name of the node is sales (xmlDoc.childNodes[2].nodeName), from the DOCTYPE tag:

  <!DOCTYPE sales SYSTEM "mydvd7.dtd">
This sales node has three child nodes. They are the ENTITY references in mydvd7.dtd:

  <!ENTITY preparedby "John Smith">
  <!ENTITY month "April">
  <!ENTITY day "Wednesday, ">
The three child nodes of sales are therefore:

  • preparedby (xmlDoc.childNodes[2].childNodes[0].nodeName)
  • month (xmlDoc.childNodes[2].childNodes[1].nodeName)
  • day (xmlDoc.childNodes[2].childNodes[2].nodeName)
Here is mydvd7.xml for your reference:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="mydvd7.xsl"?>
<!DOCTYPE sales SYSTEM "mydvd7.dtd">
  <sales>
    <summary>
      <heading>MyDVD Rental Store</heading>
      <subhead>Periodical Sales Report</subhead>
      <description>Sales Report for January, February, 
	    and &lt;&month;&gt; of 2001</description>
	  <author>author: &preparedby;</author>
	  <date>Jan 30, 2002</date>
    </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>

People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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

webref The latest from WebReference.com Browse >
Creating a Banking Application Deposit Script · Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
XPath Support for Working with XML Data in MySQL · SSDs Take Center Stage · WebPlus X4 Adds New Features for Easy Site Design