Deeper into DOM

Team Fly 

Page 478

NodeType The type of the current node (using the XmlNodeType constants —see ''Xml-NodeType enumeration" in Visual Studio Help).

Prefix The namespace prefix of the node.

Value The text value of the node.

Note that the XMLTextReader's Read method maintains a pointer within the streaming document, keeping track as the nodes flow by, leaping from node to node. At each leap, you have the opportunity to query the current node, using the Reader's properties and methods, such as the HasAttributes property used in this example.

You can stream XML in from a variety of sources, including a URL, like this:

 Dim Xreader = New XmlTextReader(http://www.myplace.xml") 

If you are one of those who are simply determined to avoid Microsoft technology, you will want to find and use other versions of SAX (and what are you doing reading this book?).

A primary distinction between classic SAX parsing and the Microsoft XMLReader is that SAX pushes the events into your source code, meaning that you are notified each time a node is read by the parse. The XMLReader pulls the XML in, offering you a bit more flexibility. For one thing, with the XMLReader you can rather painlessly access multiple input streams Another signal advantage of the XML Reader is that it includes Skip and MoveToContent methods, so you can locate nodes of interest to you more quickly. It's similar to random-access, albeit forward-only.

Deeper into DOM

The DOM is a way for programs to read and write to XML, adjusting the style, content, and structure of the XML file.

The original DOM specification is not itself a library of functions. It's merely a collection of interfaces. Interfaces are often used when a committee is concerned that a set of class and member names be standardized and enforced. XML DOM is a list of words, and you (or any other programmer) can create the source code that actually makes the interfaces do their jobs. However, I suspect you'll simply want to join the crowd and use Microsoft's version of the DOM.

The Microsoft .NET implementation of the DOM specification closely follows the official W3C DOM interfaces. The .NET XMLNodeList and XMLDocument classes—and related classes—offer both the fundamental and extended technologies specified by W3C. If you've worked with W3C DOM, you'll find its .NET implementation very familiar and easy to use. What's more, you will surely appreciate the additional features available in .NET that make working with XML both easier and less error-prone.

The DOM can be viewed as an interface to the many proprietary APIs and XML data structures, making it possible for a programmer to work with standard DOM interfaces rather than having to study proprietary APIs.

For example, Ford and GM may use different APIs to handle their XML needs, but with DOM, a programmer can move from GM to Ford and still count on a known, abstract interface that will work with either the Ford or GM APIs. In other words, DOM is a linguistic convention.

Also supporting XML are XML schemas, which assist programmers in defining their own, proprietary XML structures. Schemas, including one proposed by Microsoft, ultimately go beyond

Team Fly 


Visual Basic  .NET Power Tools
Visual Basic .NET Power Tools
ISBN: 0782142427
EAN: 2147483647
Year: 2003
Pages: 178

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net