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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:51:42+00:00 2026-06-14T05:51:42+00:00

I am beginner in C#. Simple Example of bigger case: Input: <?xml version=1.0 encoding=utf-8?>

  • 0

I am beginner in C#.

Simple Example of bigger case:

Input:

<?xml version="1.0" encoding="utf-8"?>
 <products>
  <product>
   <id>1</id>
   <name>John</name>
  </product>
  <product>
   <id>2</id>
   <name>Tom</name>
  </product>
  <product>
   <id>3</id>
   <name>Sam</name>
  </product>
 </products>
</xml>

Output(for id=1):

<id>2</id>
<name>Tom</name>

My part code try psedocode:

XDocument doc=XDocument.Parse(".............");

 var els= doc.Descendants("product");
 foreach(e in els){
     node=e.Element("id");
     if(2==node.Value){
     return e;
   }
 }

Please help,

Thanks

  • 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-14T05:51:45+00:00Added an answer on June 14, 2026 at 5:51 am

    Currently your xml file is not well-formatted – remove closing </xml> tag from your file to make it valid. And here is the query:

    int id = 1;
    XDocument xdoc = XDocument.Load(path_to_xml);
    var product = xdoc.Descendants("product")
                      .Where(p => (int)p.Element("id") == id)
                      .SingleOrDefault();
    

    This query will return whole <product> element or null if match not found.

    Also I believe product name will be enough for you to select (because you already have product id):

    var name = xdoc.Descendants("product")
                   .Where(p => (int)p.Element("id") == id)
                   .Select(p => (string)p.Element("name"))
                   .SingleOrDefault();
    

    Returns Tom for id = 2

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

Sidebar

Related Questions

A beginner's question about Lua and metatables , with a example as simple as
I am a beginner of WCF,I write a simple example of it,and the app.config
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
I am beginner trying to complete a simple JSON problem on SingPath which asks
Beginner in Android development. My code crashes. I have made a simple Java method
I'm a beginner programmer in Rails and I'm currently trying to create a simple
I am attempting to create a simple abacus for a beginner's programming course, and
PHP beginner working from a tutorial. I'm trying to do a simple upload from
I am just a beginner in ASP.NET. My question is simple, I wanna add
Im a Drupal beginner. I want to create a simple website, which has a

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.