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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:44:04+00:00 2026-05-23T01:44:04+00:00

I have an XML document in this format: <?xml version=1.0 encoding=utf-8 ?> <SupportedServices> <Service>

  • 0

I have an XML document in this format:

<?xml version="1.0" encoding="utf-8" ?>
<SupportedServices>
  <Service>
    <name>Google Weather</name>
    <active>Yes</active>
  </Service>
   ...
</SupportedServices>

And I’m trying to parse the XML file like so:

public void InitializeDropDown(string XmlFile, string xpath)
{
    XmlDocument doc = new XmlDocument();
    doc.Load(XmlFile);

    var rootNode = doc.DocumentElement;

    var serviceList = rootNode.SelectNodes(xpath);

    Parallel.ForEach(serviceList.Cast<XmlNode>(), service =>
    {
        if (Properties.Settings.Default.ServiceActive &&
            Properties.Settings.Default.ServiceName == service.InnerText)
        {
            WeatherServicesCBO.Items.Add(service.InnerText);
        }
    });
}

The issue I’m having is both values (name & active) are selected so it would look like Google WeatherYes, when All I’m wanting is Google Weather. Can someone tell me what’s wrong with my XPath (which is here):

InitializeDropDown("SupportedWeatherServices.xml", "descendant::Service[name]");
  • 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-23T01:44:05+00:00Added an answer on May 23, 2026 at 1:44 am

    The XPath should be //Service/name

    var serviceList = rootNode.SelectNodes("//Service/name");
    

    or descendant::Service/name, if you like this syntax more.

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

Sidebar

Related Questions

I have an xml document like this: <?xml version=1.0 encoding=utf-8 ?> <demographics> <country id=1
I have an XML document something like ::: <?xml version=1.0 encoding=utf-8?> <?mso-application progid=Excel.Sheet?> <Workbook
in my Web.sitemap I have this: <?xml version=1.0 encoding=utf-8?> <siteMap xmlns=http://schemas.microsoft.com/AspNet/SiteMap-File-1.0> <siteMapNode url=~/ title=Úvodní
I have an XML document looking similar to this: <items> <item cat=1 owner=14>bla</item> <item
Say I have a xml document that looks like this <foo> <bar id=9 />
I am writing an XML document in C#. I have something like this... string
I have an XML document: var xml:XML = new XML(<rootNode> <head> <meta name=template content=Default
I have a xml document on the following format and want to transform it
I have a XML document which looks something like this: <events> <event category=gymnastics subcategory=rhythmic
Suppose i have an xml document like this XML File: <document> <educationalsection> educational details

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.