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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:40:41+00:00 2026-05-15T17:40:41+00:00

I am currently working on this application(C#,WPF,LINQ2XML,.NET 4.0) that displays details for ‘Animals’. An

  • 0

I am currently working on this application(C#,WPF,LINQ2XML,.NET 4.0) that displays details for ‘Animals’. An example of this would be the application displaying the types of Animals such as ‘Birds’,’Mammals’,’Reptiles’. For each type of Animal, I will have sub-entries such as for ‘Birds’ I will have sub-entries like ‘Sparrow’,’Hawk’; for ‘Reptiles’, I will have ‘Alligators’, ‘Python’..etc..etc. The user will have the option to add comments for each of these sub-entries. An example would be for the sub-entry ‘Sparrow’, I will have an option to ‘Add Comments’. Clicking on ‘Add Comments’ will pull up a textbox where the user can enter his or her comments for ‘sparrow’. The user can insert multiple comments for a sub-entry. The user can have 1,2,3….n comments for ‘Sparrow’. This will just entail clicking on ‘Add Comments’ multiple times.

The data is preloaded with information stored in XML files. I have separate XMLs for each Animal such as Birds.xml, Mammals.xml, Reptiles.xml. Each of these will have information regarding the sub-entries. Birds.xml will have XML fragments for ‘Sparrow’ and ‘Hawk’.

I am using Linq2Xml to extract the information necessary to populate my animal objects(Model) which in turn are bound to the Presenter(I am using the Model-View-Presenter pattern) which is fed to the XAML.

I am successfully able to display the information from my XML in the view. The problem is with the ‘Comments’.

There are two things that I need to achieve here:

  1. Write all the comments added to a separate XML file (AnimalComments.xml) where I can store all the comments that have been added for all the sub-entries.

  2. In case of an application failure, I would like this same XML file(AnimalComments.xml) to pre-populate all the comments that I entered before my application crashed.

In essence I am trying to serialize the state onto the disk but in reality I don’t want the entire object graph to persist on the disk since I think I am going to add the feature of writing/adding to the AnimalComments.xml file whenever a comment is typed for a sub-entry and the focus is changed to some other sub-entry.

I was wondering if the collective wisdom of SO can help me with some elegant design guidance here to accumulate all the Comments added and persist them onto a disk in such a way that it can be used by the application later for a restore or to present in a human readable format. Any solutions requiring the use of an DBMS would not be pertinent in this situation since it is part of the requirement to store any data associated with the application on the local file system.

As Drake suggested below, there are ways to maintain the references to the Animals using some sort of Primary key but I am interested in how this should be tackled from an Object Oriented standpoint or if there are some prominent patterns that tackle this sort of a situuation.

Thanks

  • 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-15T17:40:42+00:00Added an answer on May 15, 2026 at 5:40 pm

    I have created the classes below. Please copy the code and pass to the editor !

    The animals.cs

    using System.Xml.Serialization;
    
    
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/XMLSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/XMLSchema.xsd", IsNullable=false)]
    public partial class Animals {
    
        private Animal[] animalField;
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Animal")]
        public Animal[] Animal {
            get {
                return this.animalField;
            }
            set {
                this.animalField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/XMLSchema.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/XMLSchema.xsd", IsNullable=false)]
    public partial class Animal {
    
        private string nameField;
    
        private int idField;
    
        private bool idFieldSpecified;
    
        /// <remarks/>
        public string Name {
            get {
                return this.nameField;
            }
            set {
                this.nameField = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public int ID {
            get {
                return this.idField;
            }
            set {
                this.idField = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool IDSpecified {
            get {
                return this.idFieldSpecified;
            }
            set {
                this.idFieldSpecified = value;
            }
        }
    }
    

    The AnimalComments.cs

    using System.Xml.Serialization;
    
    
    
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/AnimalComments.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/AnimalComments.xsd", IsNullable=false)]
    public partial class Animals {
    
        private Animal[] animalField;
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Animal")]
        public Animal[] Animal {
            get {
                return this.animalField;
            }
            set {
                this.animalField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/AnimalComments.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/AnimalComments.xsd", IsNullable=false)]
    public partial class Animal {
    
        private Comments commentsField;
    
        private int idField;
    
        private bool idFieldSpecified;
    
        /// <remarks/>
        public Comments Comments {
            get {
                return this.commentsField;
            }
            set {
                this.commentsField = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public int ID {
            get {
                return this.idField;
            }
            set {
                this.idField = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool IDSpecified {
            get {
                return this.idFieldSpecified;
            }
            set {
                this.idFieldSpecified = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/AnimalComments.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/AnimalComments.xsd", IsNullable=false)]
    public partial class Comments {
    
        private Comment[] commentField;
    
        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Comment")]
        public Comment[] Comment {
            get {
                return this.commentField;
            }
            set {
                this.commentField = value;
            }
        }
    }
    
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://tempuri.org/AnimalComments.xsd")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="http://tempuri.org/AnimalComments.xsd", IsNullable=false)]
    public partial class Comment {
    
        private string contentField;
    
        private int commentIDField;
    
        private bool commentIDFieldSpecified;
    
        /// <remarks/>
        public string Content {
            get {
                return this.contentField;
            }
            set {
                this.contentField = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public int CommentID {
            get {
                return this.commentIDField;
            }
            set {
                this.commentIDField = value;
            }
        }
    
        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool CommentIDSpecified {
            get {
                return this.commentIDFieldSpecified;
            }
            set {
                this.commentIDFieldSpecified = value;
            }
        }
    }
    

    Cheers.

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

Sidebar

Related Questions

I am working on an WPF application that uses a BusinessLogic layer (currently a
I am currently working on a WPF application where I would like to have
I'm currently using PrintVisual() in a wpf application to do printing. This is working
I am currently working on a WPF application that processes data in a database
I'm currently working on an ASP.NET site created by someone else. There is this
I'm currently working on my first WPF application, and I'm curious as to whether
I am currently working on an application in WPF/C# for personal use. I am
I am currently working on an MP3 player (in a WPF application) with a
I'm currently working on a WPF application, it's my first so I'm learning as
I am currently working on the WPF project which involves creating a touch-screen application

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.