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 3601832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:40:13+00:00 2026-05-18T20:40:13+00:00

I am parsing an Xml file. and I got a trouble on how to

  • 0

I am parsing an Xml file. and I got a trouble on how to use XPathNodeIterator MoveNext() more reasonable in C#2.0.

My code as this,

while (it.MoveNext())
{


string str = it.Current.GetAttribute("id", it.Current.NamespaceURI);

it.Current.MoveToChild("item", "");

// do someting....
// My XMl file is a complex Xml file. I must Move to multi layer Child with *MoveToChild()*.
// After that, I must add several *MoveToParent()* in different Layers to make sure the *it* still meet for the use of while loop.
// I think it doesn't make sense like this.
// Some time. the *it* can't still direct to my original layer. While-Loop doesn't work well.

}

I tried to declare a new XPathNodeIterator object tempIt as this,

while (it.MoveNext())
{

    XPathNodeIterator tempIt;
    tempIt= it;

    string str = tempIt.Current.GetAttribute("id", tempIt.Current.NamespaceURI);

    tempIt.Current.MoveToChild("item", "");

    // Now I chech *it* on here, I found the *it* also changed it's *current* and "position". and it's count also changed. 
    // I don't know why.

}

How can I fix this issue?

Appreciated for you comments and suggestions.

  • 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-18T20:40:14+00:00Added an answer on May 18, 2026 at 8:40 pm

    Maybe that can help

    while (nodeIterator.MoveNext())
    {
        XPathNavigator n = nodeIterator.Current;
        Console.WriteLine(n.LocalName);
    }
    
    
    XPathDocument document = new XPathDocument("books.xml");
    XPathNavigator navigator = document.CreateNavigator();
    
    XPathNodeIterator nodes = navigator.Select("/bookstore/book");
    nodes.MoveNext();
    XPathNavigator nodesNavigator = nodes.Current;
    
    XPathNodeIterator nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);
    
    while (nodesText.MoveNext())
        Console.WriteLine(nodesText.Current.Value);
    

    and books.xml

    <?xml version="1.0" encoding="utf-8" ?> 
    <bookstore>
        <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
            <title>The Autobiography of Benjamin Franklin</title>
            <author>
                <first-name>Benjamin</first-name>
                <last-name>Franklin</last-name>
            </author>
            <price>8.99</price>
        </book>
        <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
            <title>The Confidence Man</title>
            <author>
                <first-name>Herman</first-name>
                <last-name>Melville</last-name>
            </author>
            <price>11.99</price>
        </book>
        <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
            <title>The Gorgias</title>
            <author>
                <name>Plato</name>
            </author>
            <price>9.99</price>
        </book>
    </bookstore>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a string from parsing a XML file which looks like this: Fri,
I've got this XML file that I am parsing using the parser here and
I am parsing an Xml file. and I got a trouble on how to
I've used following code for parsing XML file in c++. http://www.codeproject.com/Articles/176236/Parsing-an-XML-file-in-a-C-C-program . Now I
When parsing an xml file in android, I'm doing like this: try { InputStream
I am parsing an XML file into a table and want to use the
I've got some code to convert a large (many gigabytes) XML file into another
I've got a problem with &amp when I use XML parsing with webservices which
I've got an XML file that I'm parsing with Python & outputting as Python
I am parsing xml file from url(in code below), using file_get_contents() function, and simpleXML,

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.