13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

• Connection model Both readers and navigators work on top of a datasource. Readers, however, work connected to the <strong>in</strong>put stream, which isoften a persistent storage medium like a disk file. Navigators always workon memory-mapped data sources like <strong>XML</strong> DOM or more optimized andspecialized structures. Readers must be closed when you have f<strong>in</strong>ishedwith them; navigators are simply garbage-collected when they go out ofscope. A parallel can be drawn with ADO.<strong>NET</strong> data readers and DataSetobjects. An <strong>XML</strong> data reader object, like the SqlDataReader base class, isconnected to the data source, whereas a DataSet object is a disconnectedobject.• Navigation <strong>in</strong>terface Readers are simple read-only and <strong>for</strong>ward-onlycursors. Navigators too are read-only, but they let you move <strong>for</strong>ward andbackward. The navigator's set of move methods is significantly richer. Inparticular, the set <strong>in</strong>cludes methods <strong>for</strong> go<strong>in</strong>g to the root of the underly<strong>in</strong>gdocument, <strong>for</strong> reach<strong>in</strong>g the parent node, <strong>for</strong> reach<strong>in</strong>g the next and theprevious sibl<strong>in</strong>g, <strong>for</strong> reach<strong>in</strong>g the node where the given namespace isdef<strong>in</strong>ed, and even more. In addition, you can synchronize the navigatorposition with the current position on another navigator object.• <strong>Programm<strong>in</strong>g</strong> <strong>in</strong>terface Navigators provide rich XPath capabilities andsupply methods that per<strong>for</strong>m XPath queries and return groups of relatednodes. You have a generic Select method but also ad hoc selectionmethods that specialize on the most common XPath axes, such asdescendant, ancestor, and child. In addition, navigators can simplyevaluate an XPath expression and return the value.Conceptually, XPath navigators and <strong>XML</strong> readers occupy diametrically opposedpositions <strong>in</strong> the .<strong>NET</strong> <strong>XML</strong> puzzle. Moreover, this difference clearly stems from theirnames. Navigators are thought to traverse <strong>XML</strong>-based or <strong>XML</strong>look<strong>in</strong>g data. <strong>XML</strong>readers are simply lower-level tools that you can use to read <strong>XML</strong>-based or <strong>XML</strong>look<strong>in</strong>gdata and build <strong>in</strong>-memory data structures that navigators rely on.NoteAs mentioned, <strong>XML</strong> readers and navigators work on <strong>XML</strong>based or<strong>XML</strong>-look<strong>in</strong>g data. <strong>XML</strong>-based data refers to data persisted, or justread, as well-<strong>for</strong>med <strong>XML</strong>. As we saw <strong>in</strong> Chapter 2, however, youcan use specialized reader classes to publish non-<strong>XML</strong> datathrough a virtual <strong>XML</strong> tree. Likewise, a navigator can be built towork on top of a data store that creates a virtual <strong>XML</strong> tree from non-<strong>XML</strong> data. <strong>XML</strong>-look<strong>in</strong>g data refers to just such virtual <strong>XML</strong> trees.The XPathNavigator <strong>Programm<strong>in</strong>g</strong> InterfaceLet's briefly review the properties and methods that <strong>for</strong>m the programm<strong>in</strong>g <strong>in</strong>terface ofthe XPathNavigator class. A valid <strong>in</strong>stance of the class can be obta<strong>in</strong>ed by call<strong>in</strong>g theCreateNavigator method on any .<strong>NET</strong> Framework class that implements theIXPathNavigable <strong>in</strong>terface.Properties of the XPathNavigator ClassTable 6-3 summarizes the properties of the XPathNavigator class. As you can see,most of these properties reflect the characteristics of the currently selected node.Table 6-3: Properties of the XPathNavigator ClassPropertyDescriptionBaseURIGets the base URI of the current node219

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

Saved successfully!

Ooh no, something went wrong!