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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:27:10+00:00 2026-06-07T01:27:10+00:00

I am unable to retrieve correct count of the nodes with attribute: IsTrue =

  • 0

I am unable to retrieve correct count of the nodes with attribute: IsTrue = “true” of my xml.

Code that I am using is :>>>

       Array depCnfg = (from node in xml.Descendants(Qualities).Descendants()
                           where node.Parent.Name == Qualities &&
                           (node.Attribute(ISTRUE).Value.ToString().ToLower() == "true") 
                           select { 
                           totalCount = node.Nodes().Count()}).ToArray();

XML USED: >>>

<Qualities>
 <General>
   <Tag1 IsTrue = "true">
      <SubTag1>0</SubTag1>
   </Tag1>    
   <Tag2 IsTrue = "false">
      <SubTag2>0</SubTag2>
   </Tag2>  
 </General>
</Qualities> 

Here I always get the count as 2 but actually it should be 1.
If anyone have an idea please share…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-07T01:27:12+00:00Added an answer on June 7, 2026 at 1:27 am

    You can use the following LINQ query to get the count. This is grabbing the ‘Qualities’ node and putting it into it’s own element. Then we are looking at each descendant, and check the following:

    1. Does it contain attributes
    2. Does it contain an attribute named ‘IsTrue’
    3. Does the ‘IsTrue’ attribute’s value equal ‘true’

    Then it gets the count of the elements that meet that criteria. This is assuming there is only one ‘Qualities’ node. In that case you would have to use XElement qualities = element.Element*s*(“Qualities”); .

    string sampleString = "<MAINROOT>" +
                            "<Qualities>" +
                             "<General>" +
                               "<Tag1 IsTrue = \"true\">" +
                                  "<SubTag1>0</SubTag1>" +
                               "</Tag1>" +
                               "<Tag2 IsTrue = \"false\">" +
                                  "<SubTag2>0</SubTag2>" +
                               "</Tag2>" +
                             "</General>" +
                            "</Qualities>" +
                        "</MAINROOT>";
            XElement element = XElement.Parse(sampleString);
            XElement qualities = element.Element("Qualities");
            if (qualities != null)
            {
                int trueCount = element.Element("Qualities")
                .Descendants()
                .Where(x => x.HasAttributes && x.Attribute("IsTrue") != null && x.Attribute("IsTrue").Value == "true")
                .Count();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unable to retrieve the value from DB. Please go through the code
I am unable to retrieve any data from my cfquery. Same query when i
I am unable to retrieve Status using FQL for Some Users...for Most of User
I'm unable to retrieve the latest inserted id from my SQL Server 2000 db
I am using Linq to XML with the eBay API and am unable to
In a web-application (using Flask), I get the following error: Unable to retrieve the
So: @fopen($file); Ignores any errors and continues fopen($file) or die(Unable to retrieve file); Ignores
Error: Unable to read data from the transport connection: A blocking operation was interrupted
I'm unable to execute the following prepared statement , PREPARE stmt FROM 'SELECT sb.id,sb.category,sb.make,sb.name,sb.pic,rs.slot
I'm getting an Unable to obtain public key for StrongNameKeyPair. exception using Newtonsoft's JsonConvert.SerializeObject

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.