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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:34:43+00:00 2026-05-11T19:34:43+00:00

I recently asked a question regarding how to Save a list with nested elements

  • 0

I recently asked a question regarding how to Save a list with nested elements to XML but now I am trying to write the loader for the class and have run into problems with it.

I am attempting to reverse the answer given (thanks Jon).

I believe my core LINQ query is ok, it is the recursion I am struggling with.
Here is my code so far (for clarity’s sake I have posted the entire CPP as is)

   /// <summary>
/// 
/// </summary>
public class ErrorType
{
    List<ErrorType> _childErrors;

    public String Name { get; set; }
    public bool Ignore { get; set; }

    public List<ErrorType> ChildErrors { get; protected set; }
}

/// <summary>
/// 
/// </summary>
public class ErrorList
{
    public List<ErrorType> ChildErrors { get; protected set; }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="xml"></param>
    public void FilterErrors(XElement xml)
    {
        //Convert to ErrorList
        //Write back out to XML but not writing out anything with errors
        //Send XML on its way
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="el"></param>
    /// <returns></returns>
    private XElement ErrorListToXml(ErrorList el)
    {
        // Need to declare in advance to call within the lambda.
        Func<ErrorType, XElement> recursiveGenerator = null;
        recursiveGenerator = error => new XElement
            (error.Name,
             new XAttribute("Ignore", error.Ignore),
             error.ChildErrors.Select(recursiveGenerator));

        var element = new XElement
                   ("ErrorList",
                    ChildErrors.Select(recursiveGenerator));

        Console.WriteLine(element);

        return element;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="xd"></param>
    /// <returns></returns>
    private ErrorList FromXmlToErrorList(XElement xd)
    {
        //Prepare lambda
        Func<ErrorType, XElement> recursiveGenerator = null;
        recursiveGenerator = error => new List<ErrorType>
            (error.Name,
             new XAttribute("Ignore", error.Ignore),
             error.ChildErrors.Select(recursiveGenerator));

        List<ErrorType> typeList = (from error in xd.Descendants()
                        select new ErrorType
                        {
                            Name = error.Value,
                            Ignore = bool.Parse(error.Attribute("Ignore").Value),
                            ChildErrors= error.Elements().Select()
                        }).ToList<ErrorType>();

        ErrorList el = new ErrorList();
        el.ChildErrors = typeList;
        return el;
    }

    /// <summary>
    /// 
    /// </summary>
    public void Save()
    {
        XElement xml = ErrorListToXml(this);
        xml.Save("errorlist.xml");
    }

    public void Load()
    {

    }
}

Thankyou

  • 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-11T19:34:44+00:00Added an answer on May 11, 2026 at 7:34 pm

    I got it working with something like:

        XDocument doc = XDocument.Parse(xml);
    
        Func<XElement, ErrorType> nodeReader = null;
        nodeReader = el => new ErrorType(
            el.Elements().Select(nodeReader)) {
            Name = el.Name.LocalName,
            Ignore = (bool)el.Attribute("Ignore"),
        };
    
        ErrorList list = new ErrorList(
            doc.Root.Elements().Select(nodeReader));
    

    Having added suitable constructors:

    public ErrorType(IEnumerable<ErrorType> children) {
        ChildErrors = new List<ErrorType>(children);
    }
    public ErrorType() { ChildErrors = new List<ErrorType>(); }
    
    public ErrorType(IEnumerable<ErrorType> children) {
        ChildErrors = new List<ErrorType>(children);
    }
    public ErrorType() { ChildErrors = new List<ErrorType>(); }
    

    any use?

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

Sidebar

Ask A Question

Stats

  • Questions 119k
  • Answers 119k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You have to implement it using two dictionaries. There's no… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Somebody on another forum mentioned using an image for the… May 11, 2026 at 11:52 pm
  • Editorial Team
    Editorial Team added an answer Yes, in iPhone OS 3.0. May 11, 2026 at 11:52 pm

Related Questions

I've recently asked a question on StackoverFlow about the MVC: Can the MVC Design
In designing any desktop applications, are there any general rules on how much memory
Recently I have been studying recursion; how to write it, analyze it, etc. I
I've recently been working with someone else's code and I realized that this individual

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.