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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:59:24+00:00 2026-05-18T19:59:24+00:00

I nominate me for village idiot. Why doesn’t this work: foreach (XElement clientField in

  • 0

I nominate me for village idiot.

Why doesn’t this work:

foreach (XElement clientField in _clientXml.Descendants("row").Descendants())
{
    var newFieldName =
        from sourceField in _sourceEntries.Descendants("Field")
        where (string)sourceField.Attribute("n") == (string)clientField.Attribute("n")
        select new
            {
                FieldName = ((string) sourceField.Attribute("n")),
                AcordRef = ((string) sourceField.Attribute("m"))
             };
        foreach (var element in newFieldName)
        {
            Console.WriteLine("Field Name: {0}", 
            element.FieldName, element.AcordRef);
        }
}

My source XML files are loaded with XElement.Load(myFileName). In debug, clientField has an attribute n=”Policy Number”. The first element of _sourceEntries.Descendants(“Field”) also has an attribute n=”Policy Number”. Indeed, each element in _clientXml.Descendants(“row”).Descendants() has a matching row in _sourceEntries.Descendants(“Field”). And, I know just enough to know that the select is lazy, so in debug I look at the Console.WriteLine block. No matter what I’ve tried, newFieldName is an empty set.

Just in case, here’s the first element of the client file:

<Column_0 n="Policy Number">ABC000123</Column_0>

And, here’s the fist element of the _sourceEntries collection:

<Field n="Policy Number" c="1" l="" s="" cd="" m="1805" f="" />

I know it’s going to be something simple, but I just don’t see what I’m doing wrong.

Thanks.

Randy

  • 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-18T19:59:25+00:00Added an answer on May 18, 2026 at 7:59 pm

    This accomplished what I ultimately needed to do:

    foreach (var clientField in _clientXml.Descendants("row").Descendants())
        {
            foreach (var acordMapRef in
                from sourceEntry in _clientTemplate.Descendants("SourceEntries").Descendants("Field")
                    where (string) clientField.Attribute("n") == (string) sourceEntry.Attribute("n")
                    from acordMapRef in _clientTemplate.Descendants("Acord").Descendants("Field")
                    where (string) sourceEntry.Attribute("m") == (string) acordMapRef.Attribute("id")
                    select acordMapRef)
                {
                    clientField.Attribute("n").Value = (string) acordMapRef.Attribute("n");
                }
        }
    

    But, it’s surely a candidate for ugliest code of the month. One thing I noticed in fooling around is that elements in an XElement tree don’t seem to match to XElements in an IEnumerable collection. You might notice in the original code, above, I had an object _sourceEntries. This was a collection derived from _clientTemplate.Descendants(“SourcEntries”).Descendants(“Field”). I would have thought that the two forms were essentially equivalent for my purposes, but apparently not. I’d appreciate somebody commenting on this issue.

    Thanks folks!

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

Sidebar

Related Questions

I nominate me for village idiot. Why doesn't this work: foreach (XElement clientField in
First some background: The company I work for have decided to create an iPhone
Ok, firstly I've seen this thread . But none of the solutions are very
I work in field robotics and we have a central server keeps track of
I have a Telerik grid. For each row there is a details table. The
I want to insert some value from first and second foreach into database, but
The company that I work for has and continues to put together some halfway
About 2 weeks ago I nominated a Firefox Extension I made for public release.
I'm about to re-launch a corporate website which has the same link structure for
I am looking to create a few rewrite rules. Here are the types of

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.