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

  • SEARCH
  • Home
  • 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 6075111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:27:27+00:00 2026-05-23T10:27:27+00:00

I am currently working on a .net C# solution that returns 2 sibling nodes.

  • 0

I am currently working on a .net C# solution that returns 2 sibling nodes. Using Xpath 1.0

A small example of my xml doc is this:

<PLAY>
 <SCENE>
  <SPEAKER>
  </SPEAKER>
  <LINE>
  </LINE>
  </SCENE>
</PLAY>

I am using the following code to get the line and the speaker but i dont know why i get the entire xml doc being passed in instead of just the sibling (speaker)

I have :

List speakers = new List();

XmlDocument myDoc = new XmlDocument();
myDoc.Load(textXMLFile.Text.ToString());
// Clear the text box...
textResults.Text = "";

// ADD THIS...
XPathNavigator theNav = myDoc.CreateNavigator();
XPathNavigator theNav2 = myDoc.CreateNavigator();

//XmlNodeList theNodes =
//    myDoc.SelectNodes(textXPath.Text.ToString());

textXPath.Text = "//SPEECH/LINE";
string val = "//SPEECH/SPEAKER";
XPathNodeIterator theNodes = theNav.Select(textXPath.Text.ToString());
XPathNodeIterator theNodes2 = theNav2.Select(val);

StringBuilder output = new StringBuilder();

while (theNodes.MoveNext())
{
    if (theNodes.Current.InnerXml.ToString() == "Upon my sword.")
    {
        break;
    }
    else
    {
        speakers.Add(theNodes2.Current.InnerXml.ToString());
        speakers.Add(theNodes2.Current.InnerXml.ToString());
    }
}
for (int i =0; i < speakers.Count; ++i)
{
    output.Append (speakers[i]+" ");
}
MessageBox.Show(""+output);

theNodes.Current.InnerXml.ToString() works fine for returning the line but theNodes2.Current.InnerXml.ToString() seems to return the entire XML instead of the speaker.

Any comments or suggestions are appreciated.

  • 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-23T10:27:28+00:00Added an answer on May 23, 2026 at 10:27 am

    After staring at this for awhile i totally missed that i needed to move theNodes2 also in the while loop like so


    while(theNodes2.MoveNext())

    Thanks All

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

Sidebar

Related Questions

I'm currently working on .Net projects that are using either Git or Mercurial (Hg)
I'm currently working on an Asp.net MVC Web application. In my solution, there're two
The ASP.net page I am currently working on has a drop down list that
I am currently working on a VB.NET project and the hardest thing that I
I am currently working on an ASP.NET MVC2 project. This is the first time
I am working on an ASP.NET 2.0 web solution which currently runs en-GB and
I'm working with a large (270+ project) VS.Net solution. Yes, I know this is
I am currently working on an web application that uses ASP.NET 2.0 framework. I
We're working on a SSO solution that allows users to log in via .net
Currently I am working on small application in asp.net mvc. It is a some

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.