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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:55:56+00:00 2026-05-26T18:55:56+00:00

I suspect the solution to my problem to be very easy with LINQ to

  • 0

I suspect the solution to my problem to be very easy with LINQ to XML, but I’m rather new to it and just seem to run into walls. (Also, I couldn’t find a decent tutorial which covers similar cases to mine, so if you can point me to anything there, it’s highly appreciated!)

What I need to do is this:

  • I’ve got an XML file that I have to read from, which you can find below. There’s usually just one branch in the file, which contains multiple orders. Every order has a unique code. Those orders contain multiple parameters, each of which also has a unique code.

  • I am given an order code and a parameter code, and I now have to find the right order, and within that order the right parameter.

  • For this one parameter, I need to update the “numericalValue” and “stringValue” fields.
    This is the hard part for me: because of the two conditions stated above, it looks like I have to have to introduce two intermediate variables along the way, each having one condition in its where clause, and the second one building on the first.

  • I then have to write the whole XML file back to disk, now containing my two little changes. With my intermediate variables described above, putting the whole thing together again like this looks like a particular thorny path for me.

So here’s my XML file:

<xyz version="1.2.3" 
     xmlns="http://www.mycompany.com/xyz"
     xmlns:abc="http://www.mycompany.com/xyz/abc">
  <header>
    <!-- some unimportant stuff -->
  </header>
  <body>
    <abc:abc version="1.3">
      <abc:branches>
        <abc:branch>
          <!-- some unimportant stuff -->
          <abc:orders>
            <abc:order>
check this-> <abc:orderCode>FOO</abc:orderCode>
              <abc:orderParameters>
                <abc:orderParameter>
  and this->   <abc:parameterCode>BAR</abc:parameterCode>
                  <abc:billedValue>
                    <abc:value>
       then change -> <abc:numericalValue>10</abc:numericalValue>
       these two   -> <abc:stringValue>ten</abc:stringValue>
                    </abc:value>
                  </abc:billedValue>
                </abc:orderParameter>
                <abc:orderParameter>
                  <!-- similar contents -->
                </abc:orderParameter>
                <!-- some more orderParameter instances -->
              </abc:orderParameters>
            </abc:order>
            <abc:order>
              <!-- similar contents as above -->
            </abc:order>
            <!-- some more order instances here -->
          </abc:orders>
        </abc:branch>
      </abc:branches>
    </abc:abc>
  </body>
</xyz>

As I said, I suspect the solution is quite easy, but I can’t seem to figure it out right now (especially the part where I have to write the whole thing back).

  • 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-26T18:55:56+00:00Added an answer on May 26, 2026 at 6:55 pm

    Assuming it is ensured the elements with that order code respectively parameter code you are looking for exist the following snippet should give you an idea:

        string orderCode = "FOO";
        string paramCode = "BAR";
    
        XDocument doc = XDocument.Load("file.xml");
    
        XNamespace abc = "http://www.mycompany.com/xyz/abc";
    
        XElement value = 
            doc
            .Descendants(abc + "order")
            .First(o => o.Element(abc + "orderCode").Value == orderCode)
            .Descendants(abc + "orderParameter")
            .First(p => p.Element(abc + "parameterCode").Value == paramCode)
            .Element(abc + "billedValue")
            .Element(abc + "value");
    
        value.SetElementValue(abc + "numericalValue", 20);
        value.SetElementValue(abc + "stringValue", "twenty");
    
        doc.Save(Console.Out); // do doc.Save("file.xml") to overwrite
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suspect I must be missing something very elementary but I can't seem to
Just as in title. Is suspect it is, but I couldn't find it anywhere
it seems to me that this is kind of a very easy question, but
I have run into an interesting problem with Entity Framework and based on the
I suspect this applies to general ASP.Net too but I am not sure. If
My company has a problem: we suspect that the NACHA files we are receiving
I've notice an issue - it feels like a bug but I suspect a
i have an nhibernate solution and i'm trying to do a save, but i'm
I ran into some similar questions on StackOverflow, tried the solutions, but did not
I'm looking for a lightweight CMS solution that can be integrated into an existing

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.