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.

the type. In addition, attributes and namespaces also have ad hoc methods to returntheir values: GetAttribute and GetNamespace.When you call either MoveToFirstNamespace or MoveToNextNamespace, you canspecify an argument of type XPathNamespaceScope. The XPathNamespaceScopeenumeration has three values: All, Exclude<strong>XML</strong>, and Local. All returns all namespacesdef<strong>in</strong>ed <strong>in</strong> the scope of the current node, <strong>in</strong>clud<strong>in</strong>g xmlns:xml, which is alwaysdeclared implicitly. ExcludeXml returns all namespaces def<strong>in</strong>ed <strong>in</strong> the scope of thecurrent node, exclud<strong>in</strong>g xmlns:xml. Local returns all namespaces that are def<strong>in</strong>edlocally at the current node. Whatever value you specify, the order of the namespacesreturned is not def<strong>in</strong>ed. A namespace node is a special type of attribute node. Whenselected, the navigator's Name property returns the namespace prefix. The Valueproperty, on the other hand, returns the URI.Table 6-5 lists the XPathNavigator class's methods <strong>for</strong> select<strong>in</strong>g nodes through XPathqueries.Table 6-5: XPathNavigator' Selection MethodsMethodSelectSelectAncestorsSelectChildrenSelectDescendantsDescriptionReturns the node-set selected by the specified XPathexpression. The context <strong>for</strong> the selection is theposition of the navigator when the method is called.The XPath expression can be passed <strong>in</strong> as pla<strong>in</strong> textor <strong>in</strong> a compiled <strong>for</strong>m.Selects all the ancestor element nodes of the currentnode. You can narrow the returned node-set byspecify<strong>in</strong>g a node name and a namespace URI tomatch.Selects all the child nodes of the current node. Youcan narrow the node-set by specify<strong>in</strong>g a node nameand a namespace URI to match. Attributes andnamespace nodes are not <strong>in</strong>cluded.Selects all the descendant nodes of the current node.You can narrow the node-set by specify<strong>in</strong>g a nodename and a namespace URI to match. Attributes andnamespace nodes are not <strong>in</strong>cluded.None of these methods produces any effect on the state of the XPathNavigator object.The follow<strong>in</strong>g code snippet demonstrates how to select the descendants of a node. Thecode to get the ancestors is nearly identical.// Create the underly<strong>in</strong>g XPath-enabled document objectXPathDocument doc = new XPathDocument(fileName);// Create the navigator <strong>for</strong> the specified objectXPathNavigator nav = doc.CreateNavigator();// Select the descendants of the current node that match// the specified criterianav.SelectDescendants(nodeName, nsUri, selfIncluded);222

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

Saved successfully!

Ooh no, something went wrong!