30.07.2013 Views

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

Visual Basic.NET How to Program (PDF)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

860 Extensible Markup Language (XML) Chapter 18<br />

The other event handler corresponds <strong>to</strong> but<strong>to</strong>n Select (line 190–207). Method<br />

Select (line 197) takes search criteria in the form of either an XPathExpression or<br />

a String that represents an XPath expression and returns as an XPathNodeItera<strong>to</strong>r<br />

object any nodes that match the search criteria. Figure 18.11 summarizes the XPath expressions<br />

provided by this program’s combo box.<br />

Method DisplayItera<strong>to</strong>r (defined in lines 210–220) appends the node values<br />

from the given XPathNodeItera<strong>to</strong>r <strong>to</strong> the txtSelect text box. Note that we call<br />

the String method Trim <strong>to</strong> remove unnecessary whitespace. Method MoveNext (line<br />

216) advances <strong>to</strong> the next node, which property Current (line 217) can access.<br />

18.5 Document Type Definitions (DTDs), Schemas and<br />

Validation<br />

XML documents can reference optional documents that specify how the XML documents<br />

should be structured. These optional documents are called Document Type Definitions<br />

(DTDs) and Schemas. When a DTD or Schema document is provided, some parsers (called<br />

validating parsers) can read the DTD or Schema and check the XML document’s structure<br />

against it. If the XML document conforms <strong>to</strong> the DTD or Schema, then the XML document<br />

is valid. Parsers that cannot check for document conformity against the DTD or Schema<br />

and are called non-validating parsers. If an XML parser (validating or non-validating) is<br />

able <strong>to</strong> process an XML document (that does not reference a DTD or Schema), the XML<br />

document is considered <strong>to</strong> be well formed (i.e., it is syntactically correct). By definition, a<br />

valid XML document is also a well-formed XML document. If a document is not well<br />

formed, parsing halts, and the parser issues an error.<br />

Software Engineering Observation 18.2<br />

DTD and Schema documents are essential components for XML documents used in business<strong>to</strong>-business<br />

(B2B) transactions and mission-critical systems. These documents help ensure<br />

that XML documents are valid. 18.2<br />

Expression Description<br />

/sports Matches all sports nodes that are child nodes of<br />

the document root node.<br />

/sports/game/name Matches all name nodes that are child nodes of<br />

game. The game is a child of sports, which is a<br />

child of the document root.<br />

/sports/game/paragraph Matches all paragraph nodes that are child nodes<br />

of game. The game is a child of sports, which is<br />

a child of the document root.<br />

/sports/game[name='Cricket'] Matches all game nodes that contain a child element<br />

name whose name is Cricket. The game is a child<br />

of sports, which is a child of the document root.<br />

Fig. 18.11 XPath expressions and descriptions.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!