Web Services, Part IX: Pattern-Based XML Node Selection: Context Definition(A) - Doc JavaScript | WebReference

Web Services, Part IX: Pattern-Based XML Node Selection: Context Definition(A) - Doc JavaScript


Web Services, Part IX: Pattern-Based XML Node Selection

Context Definition - Part A

When using patterns to find nodes on the DOMDocument tree, the concept of context plays a very important role. In fact, most of the search patterns are based on the search context. The context is the Node object whose selectNodes() method or selectSingleNode() method is called. Since methods are members of their object instances, the Node object instance that you call these methods with determines the context. Each node determines a different context, and applying identical patterns on different nodes yields different results. The context is like a file system directory. Results of system commands depend on the directory you are currently at.

Let's explore the different contexts that mydvd7.xml creates. The root of the DOMDocument tree is simply xmlDoc, the object created when we read the file in:

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
xmlDoc.async = false;
xmlDoc.load("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:


Next: How to define context - Part B

https://www.internet.com


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/2.html