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

  • Home
  • SEARCH
  • 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 8315497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:08:40+00:00 2026-06-08T21:08:40+00:00

I trying to get all attribute values from xml file where value doesn’t start

  • 0

I trying to get all attribute values from xml file where value doesn’t start with some text

i have this code

IEnumerable<XElement> elements =
    (from el in xmlFile.Root.Elements(elementName)
     where (string)el.Attribute(attributeName)  !StartWith("abc")
     select el);

How can i fix this

  • 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-08T21:08:41+00:00Added an answer on June 8, 2026 at 9:08 pm

    You need to use a valid expression, e.g.

    where !el.Attribute(attributeName).Value.StartsWith("abc")
    

    It’s important to understand that what goes into a LINQ where clause isn’t “magic” syntax – it’s just a normal expression, which can use the range variables declared by the query expression (el in this case). So you should have asked yourself, “If I were writing this not in LINQ, and I had a variable called el referring to an element, how would I have written an if condition to check that the attribute value didn’t start with abc?”

    (I use the explicit conversion when the attribute can be missing and I want to just get a null, but in this case you’re going to go bang when the attribute’s missing anyway, and you just want the string value, so you might as well use the Value property.)

    Note that as you’ve only got a where clause here (and a trivial select) it would probably be more readable to use the non-query-expression form:

    var elements = xmlFile.Root.Elements(elementName)
                          .Where(el => !el.Attribute(attributeName).Value.StartsWith("abc"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get values from xml, and I have problem with empty value.
I'm trying to get all of the attributes and node values from XML in
I'm trying to get a collection of values from an XML document: <root> <string
I'm trying to get the source attribute of all images withing a specific div
I am trying to get all of the video elements and their attributes from
iam trying to get all object's xpath's from loaded page via selenium something similar
Im trying to get all Leads / Contact / Accounts from the database. So
I am trying to get all Books from the server (local PHP script), that
I'm trying to get all downloads from an repo on github with help of
I'm trying to get all buffered input from cin . I tried getline ,

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.