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

  • Home
  • SEARCH
  • 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 6928285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:10:00+00:00 2026-05-27T11:10:00+00:00

I want to create a data access layer, supporting CRUD methods, with an underlying

  • 0

I want to create a data access layer, supporting CRUD methods, with an underlying storage of XML files.
I’m new to XML, and I’m not quite sure how to work with XmlDocument, XDocument, XmlSerializer etc..
Here’s my basic idea for a data access class:

public class EmployeesDao
    {
        private const string FILE_NAME = "file.xml";

            //an XDocument which contains all the employees records
        private XDocument m_XDocument;
        private XmlSerializer m_XmlSerializer;


        public TestCasesDao()
        {
            //is this correct?
                    m_XDocument = XDocument.Load(@"c:\" + FILE_NAME);
            m_XmlSerializer = new XmlSerializer(typeof(EmployeeDTO));
        }

        public void Save(IEmployee employee)
        {
            var dto = new EmployeeDTO(employee);
            //TODO: serialize the DTO, add it to the XDocument, and save to file
        }

        public IEmployee GetEmployee(string name)
        {
                    //TODO: retrieve an EmployeeDTO from my XDocument
                    return employeeDto.Convert();  //return an IEmployee
        }

            //TODO: update and delete methods...
    }

Any ideas as to how to fill in the missing gaps?

  • 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-27T11:10:01+00:00Added an answer on May 27, 2026 at 11:10 am

    For Serialization you can use Generic methods

    public static class GenericSerializer
    {
        public static string Serialize<T>(ICollection<T> listToSerialize)
        {
            MemoryStream stream = new MemoryStream();
            XmlSerializer xmlSerializer;
            try
            {
                xmlSerializer = new XmlSerializer(typeof(List<T>));
                xmlSerializer.Serialize(stream, listToSerialize);
    
                return Encoding.UTF8.GetString(stream.ToArray());
            }
            finally
            {
                stream.Close();
            }
        }
    
        public static string Serialize<T>(T objectToSerialize)
        {
            MemoryStream stream = new MemoryStream();
            XmlSerializer xmlSerializer;
            try
            {
                xmlSerializer = new XmlSerializer(typeof(T));
                xmlSerializer.Serialize(stream, objectToSerialize);
                return Encoding.UTF8.GetString(stream.ToArray());
            }
            finally
            {
                stream.Close();
            }
        }
    
      public static T Deserialize<T>(string xmlDataToeSerialize)
        {
            XmlSerializer xmlDeSerializer = new XmlSerializer(typeof(T));
            StringReader stringReader = new StringReader(xmlDataToeSerialize);
            return (T)xmlDeSerializer.Deserialize(stringReader);            
        }
    }
    

    For Update and Delete You can Retrieve the collection or object from file and edit and overwrite the existing one or you can use XPath expression for directly edit the XML

    XML/0340_XPath.htm”>http://www.java2s.com/Tutorial/CSharp/0540_XML/0340_XPath.htm

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

Sidebar

Related Questions

I want to create a data access layer that works with any data provider.
I want to create a Data Access Layer for a small application. The stored
I have to create website with business layer and data access layer. I want
i want to create a class library project which will my data access layer
Can anyone suggest a simple Data Access Layer (C# .NET)? Not keen on using
If I want to create a 3-Layer ASP.Net application (Presentation Layer, Business Layer, Data
Are there any good data access layer generators for Java? I have not used
I want to create light object data-package to pass between client and server applications.
I want to create a similar behavior to the data reader class but for
i want to create tabs according to data from MySQL database using php for

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.