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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:01:01+00:00 2026-06-15T04:01:01+00:00

How do I populate a list of case objects with two pieces of information

  • 0

How do I populate a list of case objects with two pieces of information from one or more xml files?

Every method I’ve tried has produced zero results and checking the variable gives “Enumeration yielded no results”. In my code example below, I have included (commented out) various methods I’ve tried to use to achieve this results.

If there is already an answer out there for this, please point me in that direction. I would appreciate any accompanying explanation as well.

Here are the code snippets:

private void gatherInfo(ref List<Case> Cases)
{
    List<string> XMLFileNames = new List<string>();

    foreach (string caseID in txtbxCases.Lines)
    {
        Cases.Add(new Case(caseID));
    }

    XMLFileNames.AddRange(Directory.EnumerateFiles(txtbxXMLDirectory.Text, "*", SearchOption.AllDirectories).Select(Path.GetFileName));

    string currentFileName = "";

    for (int i = XMLFileNames.Count - 1; i >= 0; i--)
    {
        currentFileName = XMLFileNames[i];
        if (currentFileName.Substring(currentFileName.Length - 4, 4) != ".xml")
        {
            XMLFileNames.RemoveAt(i);
        }
    }

    // Start of Area that doesn't work correctly
    for (int i = XMLFileNames.Count - 1; i>=0; i--)
    {
        currentFileName = XMLFileNames[i];
        //XElement currentDoc = XElement.Load(txtbxXMLDirectory.Text + "\\" + currentFileName);
        XDocument currentDoc = XDocument.Load(txtbxXMLDirectory.Text + "\\" + currentFileName);
        XElement currentDocElements = XElement.Parse(currentDoc.ToString());

        for (int i2 = Cases.Count - 1; i2>=0; i2--)
        {
            string currentCaseID = Cases[i].GetCaseID();

            IEnumerable<XElement> currentCase =
                from el in currentDocElements.Descendants("Document");
                where (string)el.Element("CaseNumber") == currentCaseID
                select el;
            ///////////////////////////////////////////////////////////
            //var currentCase =
            //    from el in currentDocElements.Descendants("IndexFields")
            //    where (string)el.Element("CaseNumber") == currentCaseID
            //    select el;
            ///////////////////////////////////////////////////////////
            //var currentCase = currentDocElements.Descendants("IndexFields")
            //    .where(x => x.Element("IndexField").Value == currentCaseID);
            ///////////////////////////////////////////////////////////

            foreach (XElement el in currentCase)
            {
                Cases[i].AddFile(el.Element("SRCFilename").Value, el.Element("XMLFilename").Value);
            }
        }
    }

    //foreach (string filename in XMLFileNames)
    //{
    //    XElement currentDoc = XElement.Load(txtbxXMLDirectory.Text + "\\" + filename);
    //
    //    foreach (var caseID in Cases)
    //    {
    //        IEnumerable<XElement> currentCase = 
    //            from el in currentDoc.ElementsAfterSelf("IndexFields")//.Elements("IndexFields")
    //            //where (string)el.Element("CaseNumber") == caseID.GetCaseID()
    //            select el;
    //
    //        foreach (XElement el in currentCase)
    //        {
    //            caseID.AddFile(el.Element("SRCFilename").Value, el.Element("XMLFilename").Value);
    //        }
    //    }
    //}
}

Below is an example XML file that includes all of the nesting that the production XML files have.

 <ImportSession>
 <Batches>
 <Batch BatchClassName="CaseFolder_XML">
 <Documents>
 <Document FormTypeName="Doc XML Form Type">
 <IndexFields>
 <IndexField Name="CaseNumber" Value="1"/>
 <IndexField Name="XMLFilename" Value="aaa.xml"/>
 <IndexField Name="SRCFilename" Value="aaa.pdf"/>
 </IndexFields>
 <Pages>
 <Page ImportFileName="c:\aaa.pdf"/>
 </Pages>
 </Document>
 <Document FormTypeName="Doc XML Form Type">
 <IndexFields>
 <IndexField Name="CaseNumber" Value="2"/>
 <IndexField Name="XMLFilename" Value="aaa.xml"/>
 <IndexField Name="SRCFilename" Value="aab.pdf"/>
 </IndexFields>
 <Pages>
 <Page ImportFileName="c:\aab.pdf"/>
 </Pages>
 </Document>
 <Document FormTypeName="Doc XML Form Type">
 <IndexFields>
 <IndexField Name="CaseNumber" Value="3"/>
 <IndexField Name="XMLFilename" Value="aaa.xml"/>
 <IndexField Name="SRCFilename" Value="aac.pdf"/>
 </IndexFields>
 <Pages>
 <Page ImportFileName="c:\aac.pdf"/>
 </Pages>
 </Document>
 <Document FormTypeName="Doc XML Form Type">
 <IndexFields>
 <IndexField Name="CaseNumber" Value="4"/>
 <IndexField Name="XMLFilename" Value="aaa.xml"/>
 <IndexField Name="SRCFilename" Value="aad.pdf"/>
 </IndexFields>
 <Pages>
 <Page ImportFileName="c:\aad.pdf"/>
 </Pages>
 </Document>
 <Document FormTypeName="Doc XML Form Type">
 <IndexFields>
 <IndexField Name="CaseNumber" Value="1"/>
 <IndexField Name="XMLFilename" Value="aaa.xml"/>
 <IndexField Name="SRCFilename" Value="aae.pdf"/>
 </IndexFields>
 <Pages>
 <Page ImportFileName="c:\aae.pdf"/>
 </Pages>
 </Document>
 <Document FormTypeName="Doc XML Form Type">
 <IndexFields>
 <IndexField Name="CaseNumber" Value="1"/>
 <IndexField Name="XMLFilename" Value="aaf.xml"/>
 <IndexField Name="SRCFilename" Value="aab.pdf"/>
 </IndexFields>
 <Pages>
 <Page ImportFileName="c:\aaf.pdf"/>
 </Pages>
 </Document>
 </Documents>
 </Batch>
 </Batches>
 </ImportSession>

The following are true in production:

  • Multiple xml files to check
  • A case may show up multiple times in an xml file
  • The same files can be added to multiple cases
  • 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-15T04:01:02+00:00Added an answer on June 15, 2026 at 4:01 am
    var xDoc = XDocument.Load("a.xml");
    var allDocs = xDoc.Descendants("Document")
                    .Select(doc=>new{
                        FormTypeName = doc.Attribute("FormTypeName").Value,
                        IndexFields = doc.Descendants("IndexField")
                                        .ToDictionary(x=>x.Attribute("Name").Value,
                                                      x=>x.Attribute("Value").Value)
                    })
                    .ToList();
    

    You can also use XPath

    string xpath = "//Document[IndexFields/IndexField[@Name='CaseNumber' and @Value='3']]";
    var docElement = xDoc.XPathSelectElement(xpath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following method : public List<string> someMethod() { // populate list of
I am trying to populate the list li from the LoginAction on to the
I'm trying to populate a List of beans from a form: public class Foo
How to populate List (string) items on console window in c++cli.
I am trying to populate a List<Image> by reading the name of the each
I am attempting to populate a list of records within the last X seconds
I'm trying to populate a list, and my question is how do you bind
Hi I'm looking to populate a list of members, based on where their club
I have a C# application that needs to populate a list of all the
UPDATE see below I am not sure how to populate a list or vector

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.