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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:16:17+00:00 2026-06-13T16:16:17+00:00

Been looking around for an answer and cant find anything – Im quite new

  • 0

Been looking around for an answer and cant find anything – Im quite new so maybe Im not hitting up the right key words?

This is a sample of the XML I am working with

<database>
<book>
<title>A</title>
<author>
  <name>1</name>
</author>
</book>
<book>
<title>B</title>
<author>
  <name>2</name>
</author>
<author>
  <name>3</name>
</author>
<author>
  <name>4</name>
</author>
<author>
  <name>5</name>
</author>
</book>
</database>

Im trying to use C# XMLDocument to grab for book A author 1 and then for book B author 1, 2, 3, 4, 5

So far the code I am working with is cycling through ALL the authors so I am getting book A author 1, 2, 3, 4, 5

The code I have so far is as follows roughly

XmlDocument doc = new XmlDocument();
doc.Load("myxmlfile");
XmlNode root = doc.SelectSingleNode("database");
XmlNodeList nodelist = root.SelectNodes("book");

foreach (XmlNode n in nodelist)
        {

XmlNodeList authors = root.SelectNodes(".//author");
book.authorstring = "";
foreach (XmlNode author in authors)
       {
       book.authorstring = book.authorstring+author.SelectSingleNode("name").InnerText + ", ";
       }
}

I read some where that if I use ” . ” before the ” // ” that it would “anchor” to the current node but it doesnt seem to be working and is cycling through all the nodes

What am I doing wrong or missing?

  • 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-06-13T16:16:19+00:00Added an answer on June 13, 2026 at 4:16 pm

    If i understand you correctly your error is in this line :

    XmlNodeList authors = root.SelectNodes(".//author");
    

    it should be

    XmlNodeList authors = n.SelectNodes(".//author");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey i have been looking around and i cant find a way to get
So I've been looking around for days now and I can not find any
I've been looking around Google and SO and haven't quite found an answer to
I've been looking around for quite some time but I just can't find the
I have been looking around for an answer to my question but couldn't find
I have been looking around for an answer to this, but couldn't really find
I have been looking around for a while, and cant seem to find the
I've been looking around and I can't find a clear answer to my situation.
I've been looking around quite a while now for an answer but since I'm
So I've been looking around for a while, and can't find an answer to

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.