spacer

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

home / experts / javascript / column104


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

Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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

http://www.internet.com

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 >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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