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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:44:33+00:00 2026-06-14T03:44:33+00:00

I´m trying for a day to make this work. I want to update a

  • 0

I´m trying for a day to make this work. I want to update a money attribute in my XML using LINQ to XML

My XML looks like this:

 <Bank>
   <Customer id="0">
     <FName>Adam</FName>
     <LName>Kruz</LName>
     <Accounts>
       <Account id="0" money="1500" />
       <Account id="1" money="6500" />
       <Account id="2" money="0" />
     </Accounts>
   </Customer>
   <Customer id="1">
     <FName>Benny</FName>
     <LName>Thoman</LName>
     <Accounts>
       <Account id="0" money="3200" />
     </Accounts>
   </Customer>
 </Bank>

I´ve beem trying with this code but with no success

 XDocument document = XDocument.Load("database.xml");

        XElement root = document.Root;

        root.Elements("Customer")
            .Where(e => e.Attribute("id").Value.Equals(customerID.ToString())).Select(e => e.Descendants("Account")
                .Where(f => f.Attribute("id").Value.Equals(this.id.ToString())).Select(f => f.Attribute("id")).First().SetValue(money.ToString()));


        document.Save("database.xml");

I´m getting an error:
The type arguments for method ‘System.Linq.Enumerable.Select(System.Collections.Generic.IEnumerable, System.Func)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.

Pls tell me how do I edit an attribute in the subtree (Accounts) of an element (Account) thanks a lot 🙁

  • 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-14T03:44:35+00:00Added an answer on June 14, 2026 at 3:44 am

    Try this:

    var query =
        from c in document.Root.Elements("Customer")
        where c.Attribute("id").Value == customerID.ToString()
        from a in c.Element("Accounts").Elements("Account")
        where a.Attribute("id").Value == this.id.ToString()
        select a;
    
    query
        .First()
        .Attribute("money")
        .SetValue(money.ToString());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been struggling all day trying to make this simple example work using socket.io.
Trying to follow this example to make it work: http://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx Here is my App.config
I spent a day trying to make Ent Lib Logging work and log anything
I am trying t make a date that comes in like this mm/dd turn
I'm trying to make work this example from http://developer.android.com/resources/tutorials/views/hello-timepicker.html , no errors while compiling
I've been playing around with autotest trying to make it work all day.. but
So I have been tearing my hair out trying to make this work. I
I've been trying all day to make git work inside emacs shells (version 24)
I'm a Mongo newbie, and trying to make this schema work. Its intended for
I have been trying all day to get this to work and have been

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.