locked
Question about caching editable data into an XMLDocument object. RRS feed

  • Question

  • User-1410783915 posted

    I need to create a desktop Windows form application using C# or VB.net. The application will read data from an XML file, and then store the data in an editable grid control, in a windows form. The application user will be able to edit the data in the grid. Once the application user has completed editing any changes, the user will press a save button. The data will only be saved if changes to the data were made, so I will have to check for any data changes before saving. 

    The XML file I am working with is around 6 megabytes and will not exceed that. Below is a tiny example of the xml document I will be working with. It is an example of the current structure where you have different categoris, and items under each category.

    So my goal is to be able to cache the XML data so that is can be edited, and then saved back into XML format.

    So here is my question. Would caching(Loading) the data into an XMLDocument object be a good approach? If it is a good approach, will there be any issues with parsing the xml data format I have below?  I ask this because I have several groups of Category tags. Also since the file is relatively small I am assuming that there won't be a problem in regards to memory resource usage.

    If caching the data into an XML document is not the best approach, should I instead load the xml data into a collection of data objects? As a final note I don't want to cache the data into a DataSet object for different reasons I won't get into.

    <xml version="1.0" standalone="yes"?>
    <Settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Category name="Database">
    <Item name="CPlatform">SQLServer</Item>
    <Item name="Server">AK1St51</Item>
    </Category>
    <Category name="Source">
    <Item name="BatchDirectory">C:\Batch</Item>
    <Item name="ArchiveDirectory">C:\Archive</Item>
    </Category>
    <Category name="UserInfo">
    <Item name="Admin">MasterAdmin</Item>
    <Item name="BasicUser">User</Item>
    </Category>
    </Settings>

    Thursday, January 17, 2019 3:29 PM

Answers

All replies

  • User475983607 posted

    Keep in mind this is an ASP.NET for for creating web applications not Windows applications.

    The solution is very simple in a Windows application though.  Created an hasChanged flag on the Windows Form (or data/business layer) responsible for making the updates.    Initially set the flag to false (the default).  Set the flag to true when the user makes a change to the in-memory data source object.

    If you are worried about concurrency (multiple users accessing the same data) then you'll need to add timestamps to the XML data records.

    Thursday, January 17, 2019 3:54 PM
  • User-1410783915 posted

    Thank you for your help. It has been several years since I worked with parsing of XMLDocument data. Do you know if there would be any issues with parsing the xml document since I have several Category tags to parse? Maybe not, but I thought I better ask now. Hopefully you are knowledgable about parsing XMLDocument data

    <Category name="Source">
    <Item name="BatchDirectory">C:\Batch</Item>
    <Item name="ArchiveDirectory">C:\Archive</Item>
    </Category>

    <Category name="Source">
    <Item name="Etc">C:\DataExample</Item>
    <Item name="EtccEtc">C:\DataExample</Item>
    </Category>

    Thursday, January 17, 2019 5:08 PM
  • User475983607 posted

    Gleeming

    Thank you for your help. It has been several years since I worked with parsing of XMLDocument data. Do you know if there would be any issues with parsing the xml document since I have several Category tags to parse? Maybe not, but I thought I better ask now. Hopefully you are knowledgable about parsing XMLDocument data

    <Category name="Source">
    <Item name="BatchDirectory">C:\Batch</Item>
    <Item name="ArchiveDirectory">C:\Archive</Item>
    </Category>

    <Category name="Source">
    <Item name="Etc">C:\DataExample</Item>
    <Item name="EtccEtc">C:\DataExample</Item>
    </Category>

    .NET has APIs for handling XML.  I recommend reading the docs and picking an approach that fits your application.  For example, read the entire XML doc into a strong type or use Linq to XML or go old school with XmlDocument and XPath.  Parsing XML in .NET is not new and there are a lot of resources a Google search away.

    https://docs.microsoft.com/en-us/dotnet/standard/serialization/examples-of-xml-serialization

    https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/linq-to-xml-overview

    https://docs.microsoft.com/en-us/dotnet/standard/data/xml/select-nodes-using-xpath-navigation

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 17, 2019 5:27 PM