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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:31:46+00:00 2026-05-11T23:31:46+00:00

I have an XML that goes like this: <?xml version=1.0 encoding=utf-8 ?> <colors> <color

  • 0

I have an XML that goes like this:

<?xml version="1.0" encoding="utf-8" ?>
<colors>
  <color index = "0">#FF0000</color>
  <color index = "1">#FF0200</color>
  <color index = "2">#FF0300</color>
  <color index = "3">#FF0500</color>
  [..]

I’m trying to select a node by its index:

XmlDocument ColorTable = new XmlDocument();
ColorTable.Load(HttpContext.Current.Server.MapPath("~/App_Data/ColorTable.xml"));
int percentage = 2;
string xpath = string.Format(@"//color[index={0}]", percentage.ToString());
//string xpath = string.Format(@"//color[index=""{0}""]", percentage.ToString());
//string xpath = string.Format(@"//color[index='{0}']", percentage.ToString());
var r = ColorTable.SelectSingleNode(xpath).Value;

I tried also the commented versions, but it does not return any result.
Any suggestion?

  • 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-11T23:31:46+00:00Added an answer on May 11, 2026 at 11:31 pm

    Use //color[@index='{0}'] instead. The @ sign means “attribute”.

    I note that you’re using a verbatim string literal by the way – the @ sign at the start of the string. There’s no need in this case – you don’t have any backslashes in the string, and it’s not multi-line. You also don’t need to explicitly call ToString on percentage – it will be converted automatically.

    string xpath = string.Format("//color[@index='{0}']", percentage);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I have an xml that goes like this: <Equipment> <ModificationDate> <Data> </Data> </ModificationDate> </Equipment>
I have an XML that goes like this: <company> <employee name=john/> <employee name=sarah/> <employee
lets say i have an xml file path.xml that goes like this: <paths> <path
I have a XML file that goes like this... (the XML file was taken
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have an xml file that looks like this; <Employee> <EmployeeName>Burt Reynolds</EmployeeName> <EmployeeTitle>Bad Ass</EmployeeTitle>
If I have a line like this ContentRepository.Update(existing); that goes into datastore repository to
I have the following shape XML: <?xml version=1.0 encoding=utf-8?> <shape xmlns:a=http://schemas.android.com/apk/res/android a:shape=ring a:innerRadiusRatio=3 a:thicknessRatio=8

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.