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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:04:19+00:00 2026-05-21T21:04:19+00:00

I have multiple Code Tables at the bottom of the XML that I am

  • 0

I have multiple Code Tables at the bottom of the XML that I am processing and I would like to lookup a code that comes from the top portion of the XML and get the CodeText from a table at the bottom of the XML.

Here are two of the CodeTables:

<CodeTable Name="Codes - Days of Week">
  <CodeText CodeValue="" /> 
  <CodeText CodeValue="1">SUNDAY</CodeText> 
  <CodeText CodeValue="2">MONDAY</CodeText> 
  <CodeText CodeValue="3">TUESDAY</CodeText> 
  <CodeText CodeValue="4">WEDNESDAY</CodeText> 
  <CodeText CodeValue="5">THURSDAY</CodeText> 
  <CodeText CodeValue="6">FRIDAY</CodeText> 
  <CodeText CodeValue="7">SATURDAY</CodeText> 
</CodeTable>
<CodeTable Name="Codes - Bus Type">
  <CodeText CodeValue="" /> 
  <CodeText CodeValue="0">NOT A BUS</CodeText> 
  <CodeText CodeValue="1">SCHOOL (PUBLIC OR PRIVATE)</CodeText> 
  <CodeText CodeValue="2">TRANSIT</CodeText> 
  <CodeText CodeValue="3">INTERCITY</CodeText> 
  <CodeText CodeValue="4">CHARTER</CodeText> 
  <CodeText CodeValue="5">OTHER</CodeText>
</CodeTable>

I am able to use the following lines of code to get to the code table:

string CodeTableName = "Codes - Days of Week";
XmlNode CodeTableNode = doc.SelectSingleNode("//CodeTable[@Name=\"" + Convert.ToString(CodeTableName) + "\"]");

And I have been able to use the following to get the CodeText for Bus Type = 0:

XmlNode CodeTextNode = doc.SelectSingleNode("//CodeText[@CodeValue=\"" + Convert.ToString(BusCode) + "\"]");
code_text = CodeTextNode.InnerText;
Console.WriteLine(code_text);    

What I would like to be able to do is put both of these together somehow? So I can get to the CodeTable I need
and then pull the correct CodeText based on the CodeValue.

  • 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-21T21:04:20+00:00Added an answer on May 21, 2026 at 9:04 pm

    If you use LinqToXml you could do the following:

    using System.Linq;
    using System.Xml.Linq;
    
    // [...]
    var codeKey = "0";
    var name = "Codes - Bus Type";
    
    var doc = XDocument.Load("bla");
    var code = doc.Descendants().Where(
            d => d.Name == "CodeText" &&
            d.Parent.Attribute("Name").Value == name &&
            d.Attribute("CodeValue").Value == codeKey).FirstOrDefault().Value;
    

    In productive code I’d make sure that you first check for null before the last .Value call. But otherwise this should work.

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

Sidebar

Related Questions

I would like to have multiple users that share the same tables in the
I have multiple classes that all derive from a base class, now some of
I have many tables that use Lookup/Enum references for most of their column values.
I have multiple tables on my page that contain a checkbox. Immediately following the
I am writing code that pulls data from database tables and writes them to
I have to deploy my php/html/css/etc code to multiple servers and i am looking
My code is built to multiple .dll files, and I have a template class
my solution has multiple projects and in one of them I have the code
I have multiple projects in a couple of different workspaces. However, it seems like
I have multiple threads (C# application running on IIS) running that all need 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.