Datasheet
The word path refers to XPath’s use of a location path to locate the desired parts of an XML document.
This concept is similar to the path used to locate a file in the directories of a file system, or the path speci-
fied in a URL in a Web browser to locate a specific page in a complex Web site. One of the most important
uses of XPath is in conjunction with XSLT. For example, you can utilize XPath to query XML documents
and then leverage XSLT to transform the resulting XML into an HTML document (for display in any
format desired) or any other form of XML (for import into another program that may use a different set of
XML tags). XPath is very powerful in that you can not only use it to query an XML document for a list of
nodes matching a given criteria, but also apply Boolean operators, string functions, and arithmetic
operators to XPath expressions to build extremely complex queries against an XML document. XPath also
provides functions to do numeric evaluations, such as summations and rounding. You can find the full
W3C XPath specification at
http://www.w3.org/TR/xpath. The following list shows some of the
capabilities of the XPath language:
❑ Find all children of the current node.
❑ Find all ancestor elements of the current context node with a specific tag.
❑ Find the last child element of the current node with a specific tag.
❑ Find the nth child element of the current context node with a given attribute.
❑ Find the first child element with a tag of
<tag1> or <tag2>.
❑ Get all child nodes that do not have an element with a given attribute.
❑ Get the sum of all child nodes with a numeric element.
❑ Get the count of all child nodes.
The preceding list just scratches the surface of the capabilities available using XPath. Once again, the
.NET Framework provides excellent built-in support for XPath queries against XML DOM documents
and read-only XPath documents. You will see examples of this in later chapters.
SAX
In sharp contrast to XML DOM, the Simple API for XML (SAX) approaches its manipulation of a docu-
ment as a stream of data parts instead of their aggregation. SAX requires the programmer to decide what
nodes the application will recognize to trigger an event. DOM uses a parallel approach to the document,
meaning it can access several different level nodes with one method. SAX navigates an XML document
in serial, starting at the beginning and responding to its contents once for each node and in the order
they appear in the document.
Because it has a considerably smaller memory footprint, SAX can make managing large documents (usu-
ally one measured in megabytes) and retrieving small amounts from them much easier and quicker.
Because a SAX application approaches a document in search of nested messages for which it generates
responses, aborting a load under SAX is easier than doing so under DOM. The speed by which you can
find a certain type of node data in a large document is also improved.
19
Introduction to XML
04_596772 ch01.qxd 12/13/05 11:17 PM Page 19