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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:32:04+00:00 2026-06-18T02:32:04+00:00

I am not so far good in linq so was trying to write Linq

  • 0

I am not so far good in linq so was trying to write Linq query to check whether child topic node exist if code=”111″ && isDisplay=”Y” or not.i am using .Any condition in Second method but still i am not sure about this.

static void Main(string[] args)
{
    XElement rootElement = XElement.Load("TestXML.xml");
    int StyCode = 1;
    var lv1s = from lv1 in rootElement.Descendants("Class")
               where lv1.Attribute("Code").Value.Equals("001")
               select (from ltd in lv1.Descendants("Subject")
                       where ltd.Attribute("Course").Value.Equals("Engish")
                       select GetChildFromSubject(StyCode, ltd)).FirstOrDefault();

       }

private static bool GetChildFromSubject(int styCode, XElement subject)
{
    if (styCode == 0)
        return subject.Attribute("SpeciaGuest").Value.Equals("Y");
    else
    {
        //Below is the main issue with and condition on attributes.
        return subject.Attribute("AllTeachers").Value.Equals("Y") ||
               subject.Elements("Topic").Attributes("Code")
               .Any(x => x.Value.Equals("111")) &&       subject.Elements("Topic").Attributes("isDisplay")
                        .Any(y => y.Value.Equals("Y"));
    }
}

Below is XML file

<Class Code="002">
    <Subject Course="Math" AllTeachers='Y' SpeciaGuest='N'>
      <Topic Code="1" isDisplay="Y">LAW1</Topic>
      <Topic Code="2" isDisplay="Y">
        LAW2
      </Topic>
      <Topic Code="3" isDisplay="N">
        LAW3
      </Topic>
    </Subject>
    <Subject Course="Engish" AllTeachers='N' SpeciaGuest='Y'>
      <Topic Code="111" isDisplay="Y">LAW1</Topic>
    </Subject>
    <Subject Course="History" AllTeachers='Y' SpeciaGuest='Y'></Subject>
  </Class>
  • 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-18T02:32:05+00:00Added an answer on June 18, 2026 at 2:32 am

    Per your comment:

    Magnum : i want to check topic node exist if code=”111″ && isDisplay=”Y”

    If you’re trying to return the TOPIC node if code=111 and isDiaply=Y, then here is the LINQ query in one shot:

    List<XElement> subjects = template.Descendants("Subject")
                .Elements("Topic")
                    .Where(elementNode => elementNode.Attribute("Code").Value == "111" && elementNode.Attribute("isDisplay").Value == "Y").ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying and so far not succeeding in making a query with a
Im not good at math, I could find everything so far, but not this
I m just starting with microsoft (MVC,C#, LINQ), so far so good, but i
I am using Linq extensively in my project, so far performance is good, i
The WPF ListBox doesn't have a DoubleClick event, at least not as far as
As far as I can see this is not the case, however, I thought
As far as I know both FireFox and Safari can not work with Kerberos
As far as I know the System.ComponentModel.DataAnnotations.DataTypeAttribute not works in model validation in MVC
I'm not that familiar with PHP so far but already succeeded in registring a
As far as I know, VS2008/MSBuild do not suport multithreaded compilation of C# projets.

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.