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

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

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

Table 6-4: XPathNavigator Move MethodsMethodMoveToNextMoveToNextAttributeMoveToNextNamespaceMoveToParentMoveToPreviousMoveToRootDescriptionnamespace node is the prefix.Moves to the next sibl<strong>in</strong>g of the current node.Moves to the next attribute of the current node.Moves to the next namespace <strong>in</strong> the currentelement node.Moves to the parent of the current node.Moves to the previous sibl<strong>in</strong>g of the currentnode.Moves to the root node of the document.The MoveTo method attempts to synchronize the current <strong>in</strong>stance of theXPathNavigator object with another <strong>in</strong>stance. MoveTo returns true or false depend<strong>in</strong>gon the success or failure of the operation. Note that the synchronization always fails ifthe two navigators are actually implemented through different and <strong>in</strong>compatible classes.Two navigators have different implementations if the other navigator can't be cast to thecurrent type.Consider the follow<strong>in</strong>g pseudocode:public bool MoveTo(XPathNavigator other){InternalXPathNavigator nav = other as InternalXPathNavigator;if (nav == null)return false;}⋮In C#, the as operator behaves like a cast except that, when the conversion fails, itreturns null rather than rais<strong>in</strong>g an exception. In the preced<strong>in</strong>g pseudocode, theInternalXPathNavigator class represents the actual (and <strong>in</strong>ternal) navigator class yougot from the document's CreateNavigator method. Each XPathenabled document classactually <strong>in</strong>stantiates a custom navigator class and returns that class when you call itsCreateNavigator method.The MoveTo method also might fail when the two navigators share the sameimplementation but po<strong>in</strong>t to different document <strong>in</strong>stances. What happens <strong>in</strong> this case,however, depends on the specific implementation. In particular, MoveTo fails when thedocument class is XmlDocument or XmlDataDocument, but not when the underly<strong>in</strong>gdata object is an <strong>in</strong>stance of XPathDocument.Namespace Node NavigationAs you might have noticed <strong>in</strong> Table 6-4, there are three types of move methods: <strong>for</strong>element, attribute, and namespace nodes. Call<strong>in</strong>g the wrong method on a nodecauses the whole operation to fail, and there is no change <strong>in</strong> the position of thenavigator. Only MoveTo and MoveToRoot can be called on any node, irrespective of221

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

Saved successfully!

Ooh no, something went wrong!