March 6, 2002 - A Good Exercise for DOMDocument Accessing Skills | WebReference

March 6, 2002 - A Good Exercise for DOMDocument Accessing Skills

Yehuda Shiran March 6, 2002
A Good Exercise for DOMDocument Accessing Skills
Tips: March 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

The data node of mydvd7.xml is the root of a deep tree, as it holds the actual data of the dvds. The data node has three child nodes, one for every month of the report:

Each month has five child nodes: one for its name and four for its four week proceeds. Here are the child nodes of January:

  • name (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[0].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[1].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[2].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[3].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[4].nodeName)
Similarly, here are the child nodes of February:

  • name (xmlDoc.childNodes[3].childNodes[1].childNodes[1].childNodes[0].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[1].childNodes[1].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[1].childNodes[2].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[1].childNodes[3].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[1].childNodes[4].nodeName)
March's three child nodes are:

  • name (xmlDoc.childNodes[3].childNodes[1].childNodes[2].childNodes[0].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[2].childNodes[1].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[2].childNodes[2].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[2].childNodes[3].nodeName)
  • week (xmlDoc.childNodes[3].childNodes[1].childNodes[2].childNodes[4].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>