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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:03:32+00:00 2026-05-11T04:03:32+00:00

Me again… I have an XML File that contains different categories which I would

  • 0

Me again… I have an XML File that contains different categories which I would like to query for different attributes.

        <item>                   <title>Industries</title>                   <category type='Channel'>Automotive</category>                   <category type='Type'>Cars</category>                   <category type='Token'>Article</category>                   <category type='SpecialToken'>News</category>                   <guid>637f0dd7-57a0-4001-8272-f0fba60feba1</guid>         </item> 

IN SQL I would write something like.

select * from articles where channel = 'Automative' AND type = 'Cars' etc. etc. 

How can I achieve this with linq? I tried the following query but it returns null. If I combine the two attributes with the ‘OR’ || operator I would get the results, but with all double results if an item matches both criteria.

var articleList = (from item in doc.Descendants('item')                           from _category in item.Elements('category')                          where _category.Value == valueCboChannel && _category.Attribute('domain').Value == 'Channel'                          && (_category.Value == valueCboSubChannel && _category.Attribute('domain').Value == 'SubChannel')                           select new                          {                               Title = item.Element('title').Value,                              Guid= item.Element('guid').Value,                              description = item.Element('description').Value,                              link = item.Element('link').Value                          }).ToList();              ListView1.DataSource = articleList;             ListView1.DataBind();                
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T04:03:33+00:00Added an answer on May 11, 2026 at 4:03 am

    I’d simplify it with an extension method to do the tricky lookup:

    (updated 12/02/09 to exclude empty elements)

    static string CategoryValue(this XElement element, string type) {     var category = element.Elements('category').FirstOrDefault(         c => (string)c.Attribute('type') == type             && !string.IsNullOrEmpty(c.Value)); // UPDATE HERE     return category == null ? null : category.Value; }  static void Main() {     XDocument doc = XDocument.Parse(xml);     var qry = from item in doc.Descendants('item')               where item.CategoryValue('Channel') == 'Automotive'               && item.CategoryValue('Type') == 'Cars'               select item;     foreach (var node in qry)     {         Console.WriteLine(node.Element('guid').Value);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Once again, I have a problem for which I would like to shave off
Again a simple thing. I have a stylesheet that parses XML and XSL files.
again have problem with opends now i would like to save unicode in the
Once again a very beginner-ish question, but here I go: I would like to
Here we go again, the old argument still arises... Would we better have a
Once again, our best loved i=i-- -like issues. In C99 we have: 6.5 Expressions
Once again I need some help. I'm working with a table that contains 3
Again and again I have the case that during development, the Android SDK suddenly
again I have a question that is not so easily googlable. Let's assume BIOS
Again same question title but requirement is somewhat different. We have implemented push notification

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.