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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:19:30+00:00 2026-05-20T18:19:30+00:00

XML <Questions> <Question> <Id>1</Id> <Text>aaa</Text> </Question> <Question> <Id>2</Id> <Text>bbb</Text> </Question> </Questions> Code question=aaa; var

  • 0

XML

<Questions>
   <Question>
      <Id>1</Id>
      <Text>aaa</Text>
    </Question>
    <Question>
      <Id>2</Id>
      <Text>bbb</Text>
   </Question>
</Questions>

Code

question="aaa";

var doc = XDocument.Load(Server.MapPath(".") + "\\Questions.xml");
        var elements = from element in doc.Descendants("Question")
                       let txt = element.Element("Text")
                       where question.CompareTo (txt)==0 
                       select new
                       {
                           Id = element.Element("Id").Value,
                       };

This code elements.count()==>0

I would Like that select from xml where txt=='aaa'

  • 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-20T18:19:31+00:00Added an answer on May 20, 2026 at 6:19 pm

    The line let txt = element.Element("Text") returns a XElement instead of the text so your CompareTo condition will blow up instead of checking the text values.

    Instead you can get the value of the node via the .Value property.

    ...
    let txt = element.Element("Text").Value
    ...
    

    The line var elements = from element in doc.Descendants("Question") will successfully lookup the elements but as a practice you might want to go from the root node or relative hierarchy.

    ...
    var elements = from element in doc.Root.Descendants("Question")
    ...
    

    The rest of the code seems fine (less exception handling).

    The following worked for me…

    string xml = @"<Questions>
       <Question>
          <Id>1</Id>
          <Text>aaa</Text>
        </Question>
        <Question>
          <Id>2</Id>
          <Text>bbb</Text>
       </Question>
    </Questions>";
    
    string question = @"aaa";
    var doc = XDocument.Parse(xml);
    var elements = from element in doc.Root.Descendants("Question")
               let txt = element.Element("Text").Value
               where question.CompareTo(txt)==0 
               select new
               {
                   Id = element.Element("Id").Value,
               };
    
    Console.WriteLine(elements.Count()); //1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

XML: 1 aaa 2 bbb Code var doc = XDocument.Load (Server.MapPath(.) + \\Questions.config); var
XML: <Questions> <Question> <Id>1</Id> <Text>aaa</Text> <Reserver /> </Question> <Question> <Id>2</Id> <Text>bbb</Text> <Reserver /> </Question>
Script xml=<?xml version='1.0' encoding='utf-8'?><Questions> <Question><Id>1</Id><Text>name1</Text></Question></Questions>; var doc=$($.parseXML(xml)); $(doc).find(Question).each(function() { alert($(this).find('Text').text()); $('<%=sctQuestion.ClientID %>'). append($(<option></option>). attr(value,$(this).find('Text').text()).
I have an xml file that looks something like this <questions> <question> <text>What color
I have the following XML: <questions> <question text=This is a test question?> <answer value=Yes>
I have an XML file format that contains a structure of questions: <question id=q101>
I have followed the instructions from this SO question: How to change the text
I make program to read xml file by using traditional JavaScript. <script type=text/javascript> var
For another question I have created some XML related code that works on my
Extending this question: How to Create several files from a list in a text

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.