Web Services, Part IX: Pattern-Based XML Node Selection: Context Definition (B) - Doc JavaScript
Web Services, Part IX: Pattern-Based XML Node Selection
Context Definition - Part B
The fourth node of mydvd7.xml
is where the data tree hangs. The name of the top-level child is sales (xmlDoc.childNodes[3].nodeName)
, from the sales
tag:
<sales> . . . </sales>
The sales
node has two child nodes:
summary (xmlDoc.childNodes[3].childNodes[0].nodeName)
data (xmlDoc.childNodes[3].childNodes[1].nodeName)
The summary
node has five child nodes:
heading (xmlDoc.childNodes[3].childNodes[0].childNodes[0].nodeName)
subhead (xmlDoc.childNodes[3].childNodes[0].childNodes[1].nodeName)
description (xmlDoc.childNodes[3].childNodes[0].childNodes[2].nodeName)
author (xmlDoc.childNodes[3].childNodes[0].childNodes[3].nodeName)
date (xmlDoc.childNodes[3].childNodes[0].childNodes[4].nodeName)
The summary
's child nodes do not have any lower-level child nodes. The data
node is the root of a much deeper tree, as it holds the actual data of the dvds. The data
node has three child nodes, one for every month of the report:
month (January) (xmlDoc.childNodes[3].childNodes[1].childNodes[0].nodeName)
month (February) (xmlDoc.childNodes[3].childNodes[1].childNodes[1].nodeName)
month (March) (xmlDoc.childNodes[3].childNodes[1].childNodes[2].nodeName)
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)
The name
nodes have child nodes of their own, one per node. They hold the name
's text property:
January (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[0].childNodes[0].text)
February (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[1].childNodes[0].text)
March (xmlDoc.childNodes[3].childNodes[1].childNodes[0].childNodes[2].childNodes[0].text)
Next: How to select nodes
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: February 25, 2002
Revised: February 25, 2002
URL: https://www.webreference.com/js/column104/3.html