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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:04:54+00:00 2026-05-25T03:04:54+00:00

I have a Xml file:- <Users> <User Name=abc Pass=asp></User> <User Name=def Pass=net></User> </Users> I

  • 0

I have a Xml file:-

<Users>
  <User Name="abc" Pass="asp"></User>
  <User Name="def" Pass="net"></User>
</Users>

I have to write a code where two user input values entered in the textbox eg:- usernm and pass are to be checked against the attribute of the particular node and its pass for returning a true value.

i want to check d inputs usernm and pass against the attribute name which if matches will check the pass as well and return a true of fasle value.

Please suggestsomething without using iterator and inumerable.

  • 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-25T03:04:55+00:00Added an answer on May 25, 2026 at 3:04 am

    Well LINQ to XML is pretty much based on iterators, so it’s hard not to use them at all… but I suspect you want something like:

    return doc.Descendants("User")
              .Any(x => (string) x.Attribute("Name") == targetName &&
                        (string) x.Attribute("Pass") == targetPassword);
    

    Or assign it to a variable:

    bool foundUser = doc.Descendants("User")
                        .Any(x => /* code as before */);
    

    or if you really want it as an if condition:

    if (doc.Descendants("User")
           .Any(x => /* code as before */))
    {
    }
    

    Personally I’d either extract this to a separate method (which can just be the return statement as per the first example) or use a local variable for simplicity – I don’t like my if conditions being this complicated.

    That will determine whether any User element matches the relevant attributes. It doesn’t give any information about the element which matched, of course. For that you’d want to use FirstOrDefault instead of Any, and then if the element is non-null, that’s the first match.

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

Sidebar

Related Questions

i have the following xml file <?xml version=1.0 encoding=utf-8?> <Users> <User> <Name>John Smith</Name> <test>
We have a PageRoles xml file which contains the page path and the user
I have some code that uses Open XML to open up a .docx file,
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have this page: http://www.ryancoughlin.com/files/xml/ - if you select User -> Someones name You
Summary We have an ASP.NET application that allows users to query a SQL Server
I have an xml file which contains query details like <queries> <query> <name>GetStudentById</name> <statement>select
I have an xml file with multiple nodes: <member> <screen_name>User</screen_name> <username>username</username> </member> What I
What is the easiest way to convert xml to html? I have xml file
I have an xml file providing data for a datagrid in Flex 2 that

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.