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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:35:47+00:00 2026-06-11T15:35:47+00:00

<Category id=1> <MyLines> <Line GroupID=0 Cache=15 /> <Rect GroupID=0 Cache=16/> <Ellipse GroupID=0 Cache=16/> </MyLines>

  • 0
<Category id=1>
<MyLines>
      <Line GroupID="0" Cache="15" />
  <Rect GroupID="0" Cache="16"/>
  <Ellipse GroupID="0" Cache="16"/>
</MyLines>

My XML document contains many Category tags. Could you please let me know what is the best way to get each of the sub elements of MyLines whose Cache = 16 and remove them.

I am looking to achieve this using linq.

I was trying as below:

       var q = from node in doc.Descendants("MyLines")
                let attr = node.Attribute("Cache")
                where attr != null && Convert.ToInt32(attr.Value) == 16
                select node;
        q.ToList().ForEach(x => x.Remove());
  • 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-11T15:35:48+00:00Added an answer on June 11, 2026 at 3:35 pm

    I have tested the following code:

    string xml = 
    @"<Category id=""1"">
    <MyLines>
        <Line GroupID=""0"" Cache=""15"" />
    <Rect GroupID=""0"" Cache=""16""/>
    <Ellipse GroupID=""0"" Cache=""16""/>
    </MyLines>
    </Category>";
    
    void Main()
    {
        var doc = XDocument.Parse(xml);
    
        doc.Descendants("MyLines")
        .Elements()
        .Where(el => el.Attribute("Cache").Value == "16") 
        .ToList()
        .ForEach(el => el.Remove());
    
        doc.Root.ToString().Dump();
    }
    

    It prints:

    <Category id="1">
       <MyLines>
          <Line GroupID="0" Cache="15" />
       </MyLines>
    </Category>
    

    The problem is that you were looking for the Cache attribute on the MyLines elements instead of on the MyLines elements’ children.

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

Sidebar

Related Questions

I have a category system that is related many-to-many with posts. How can I
foreach(var category in categories) { a.AddRange(_db.Articles.Where(c => c.Categories.Contains(category))); } The code runs fine, yet
I have a Category and Subcategory model. Category has many subcategories and Subcategory belongs
A category tree like this: root_1 sub_1 sub_2 ... to sub_20 Every document has
In category.xml I'm changing the reference name in: <reference name=left> <block type=catalog/layer_view name=catalog.leftnav before=-
Table Category (c) has a 1:many relationship with Table Question: a Category can have
shop.category: Reverse query name for field 'parent_category' clashes with related field 'Category.category'. Add a
I have a category/file tree structure. Both categories and files can have parents, so
I created a Category on UIView with a method who's purpose it to create
pro_id | Category --------+---------   25   | electronics   27   | Electrical

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.