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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:53:12+00:00 2026-05-31T15:53:12+00:00

Struggling with one aspect of my code that I hope someone could shed some

  • 0

Struggling with one aspect of my code that I hope someone could shed some light on.

I’m pulling an xml document multiple times from within a simple foreach loop. I want to append my linq query to a list, but it is rewriting the list each time. Here’s the code:

IEnumerable<TranList> tList;
foreach (var t in otherList)
{
         //pulling xml data from service here - code not shown
         XDocument xDoc = XDocument.Parse(xmlFromService);
         tList = from x in xDoc.Descendants("Items")
         select new TranList
         {
             BusDate = x.Descendants("BusDate").First().Value,
             SeqNum = x.Descendants("SeqNum").First().Value,
             Amount = x.Descendants("Amount").First().Value,
             Credit = x.Descendants("Credit").First().Value
         };
}

and here’s my xml for reference:

<Items>
    <DbAmount>25,465.58</DbAmount>
    <DBCount>296</DBCount>
    <CrAmount>.00</CrAmount>
    <CrCount>0</CrCount>
    <Item>
        <ID>0</ID>
        <BusDate>20090126</BusDate>
        <BlockNum>729</BlockNum>
        <SeqNum>2</SeqNum>
        <RelSeqNum>0</RelSeqNum>
        <Serial />
        <Routing>211690953</Routing>
        <Account>123456789</Account>
        <Amount>30.00</Amount>
        <Currency>USD</Currency>
        <Credit>DEBIT</Credit>
        <Onus>TRANSIT</Onus>
    </Item>
    <Item>
    . . . . . . . . . . . . . . .
    </Item>
    . . . . . . . . . . . . . . .
</Items>

Thanks for any help!

  • 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-31T15:53:14+00:00Added an answer on May 31, 2026 at 3:53 pm

    You are currently re-assigning tList every time, instead concatenate:

    tList = (from x in xDoc.Descendants("Items")
            select new TranList
            {
                BusDate = x.Descendants("BusDate").First().Value,
                SeqNum = x.Descendants("SeqNum").First().Value,
                Amount = x.Descendants("Amount").First().Value,
                Credit = x.Descendants("Credit").First().Value
            }).Concat(tList);
    

    But why do you need a foreach in the first place? You are not even using the loop variable currently so this doesn’t make much sense as is.

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

Sidebar

Related Questions

here's an easy one (that I'm struggling with)! I have a textarea, a button,
I've been struggling with this one for a few days now (but that's only
I have been struggling with this one, hopefully it will help someone else. Whilst
need some advice on this one as im struggling abit and cannot figure it
I seem to be struggling with this one and I was hoping someone cold
I'v been struggling with this one for some time so any hint or suggestion
I've been struggling with this one SQL query requirement today that I was wondering
I'm new to regex and have been struggling with one, and have abstracted my
Im struggling with this one. I have a list of items and on a
I've been struggling with this one for a couple of days now. My current

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.