Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6856953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:57:14+00:00 2026-05-27T01:57:14+00:00

This is an example of using XPathNavigator from Microsoft . using System; using System.Xml;

  • 0

This is an example of using XPathNavigator from Microsoft.

using System;
using System.Xml;
using System.Xml.XPath;

// http://support.microsoft.com/kb/308343
namespace q308343 { 
    class Class1 {
        static void Main(string[] args) {

            XPathNavigator nav; 
            XPathDocument docNav; 

            docNav = new XPathDocument(@"Books.Xml");
            nav = docNav.CreateNavigator();
            nav.MoveToRoot();

            //Move to the first child node (comment field).
            nav.MoveToFirstChild();

            do {
                //Find the first element.
                if (nav.NodeType == XPathNodeType.Element) {
                    //Determine whether children exist.
                    if (nav.HasChildren == true) {

                        //Move to the first child.
                        nav.MoveToFirstChild();

                        //Loop through all of the children.
                        do {
                            //Display the data.
                            Console.Write("The XML string for this child ");
                            Console.WriteLine("is '{0}'", nav.Value);

                            //Check for attributes.
                            if (nav.HasAttributes == true) {
                                Console.WriteLine("This node has attributes");
                            }
                        } while (nav.MoveToNext()); 
                    }
                }
            } while (nav.MoveToNext()); 
            //Pause.
            Console.ReadLine();
        }
    }
}

I think this code has a bug that it doesn’t execute MoveToParent() to go up to one level when there is no elements to show.

nav.MoveToFirstChild();

//Loop through all of the children.
do {
    ....
} while (nav.MoveToNext()); 

nav.MoveToParent(); <-- This seems to be missing.

However, when I compile/execute this example, it works fine with and without nav.MoveToParent().

Is MoveToParent()/MoveToFirstChild() pair necessary with XPathNavigator? Is it OK not to use MoveToParent() because the second execution of MoveToNext() works as MoveToParent() when the first execution of MoveToNext() returns false?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:57:15+00:00Added an answer on May 27, 2026 at 1:57 am

    In this code, after we go through all of the children of the root node, there is no more work to be done, there can’t be more than one root node. So there is no need to MoveToParent(), we can just exit. Which is exactly what the code does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From this example http://www.senchafiddle.com/#dPZn0 This displays a first panel, then a second one... using
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I used this example (http://reecon.wordpress.com/2010/04/25/uploading-files-to-http-server-using-post-android-sdk/) to upload file from android device to server, it
How can i extract key value pairs from this xml example using linq: <foo>
I'm using this example http://demos.flesler.com/jquery/scrollTo/ . I've managed to implement it but when my
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I'm using this plugin: http://www.jeremymartin.name/projects.php?project=kwicks And my code follows this example: http://www.jeremymartin.name/examples/kwicks.php?example=7 I'm using
I have a url in this form http://www.example.com/data/45 . How do I get the
http://jsfiddle.net/nFFuD/ I'm trying to animate the search field in this example using jquery, making
For example using this Wikipedia dump: http://en.wikipedia.org/w/api.php?action=query&prop=revisions&titles=lebron%20james&rvprop=content&redirects=true&format=xmlfm Is there an existing library for Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.