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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:52:57+00:00 2026-05-19T15:52:57+00:00

I’ve come across a dilemma. My C# app uses a custom file format that

  • 0

I’ve come across a dilemma. My C# app uses a custom file format that needs to be human-editable in a text editor, but can also be editable via the GUI in my app. This file would represent a top-level object (call it TopObject), which contains several smaller objects, which in turn contain other objects, and so forth. All of the data contained in these objects is provided in the file.

I’m stuck as how to go about the issue of loading/saving these files. C# serialization doesn’t work for me, as it breaks human-editability (binary serialization) or has “issues” with serializing collections of base classes (XML and DataContract serialization, which add text to disambiguate derived classes when serializing a base class, which makes the files more brittle to human-editing); if it weren’t for needing to have the files editable by hand, it would have been the ticket. I’ve been looking into parser generators such as GOLD and GPLEX/GPPG to parse and convert the file into the objects they represent, and it looks promising, but this only covers the one direction of loading files, not ensuring they’re saved in a correct format when writing them out.

What would be great would be a way to specify a grammar that handles both:
1) Reading a file with a specified structure and converting it into a TopObject and all its contained objects, and
2) Given a TopObject, writing its state out to a file with that same structure.
Pretty much, a single grammar that enforces import structure as well as enforces output structure.

Are there any such tools or frameworks that could help me? Is this something feasible, or am I overthinking this way too hard and there’s an easier way?

  • 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-19T15:52:58+00:00Added an answer on May 19, 2026 at 3:52 pm

    I would still use XML, but just write your own serializer. You could use the XML reader/writer classes in .Net to create a simple XML format:

    <TopObject>
        <SubObject>
            <SubObject>
                etc.
            </SubObject>  
            <SubObject>
                etc.
            </SubObject>
        </SubObject>
        <SubObject></SubObject>
    </TopObject>
    

    I don’t know if you consider this human-readable enough, but it’s better that the stuff the .Net serializer creates. It would be easy enough to read/write recursively.

    Example:

    Here is a simplistic example that you can adapt. Assume I have this class:

    public class Node {
        public Node(String _SomeProperty) {
            this.SomeProperty = _SomeProperty;
        }
    
        public String SomeProperty;
    
        public List<Node> Children = new List<Node>();
    }
    

    Each Node has a property, called SomeProperty. It can also have children; more Nodes in the Children property.

    Here is the main from a Console application that creates some data out of this class to serialize:

    static void Main(string[] args) {
        // Make some data for testing
        Node baseObject = new Node("This is the base class");
    
        List<Node> Children = new List<Node>(){
            new Node("This is a child"),
            new Node("This is another child")
        };
    
        baseObject.Children = Children;
    
        Node aSubChild = new Node("This is a child of a child");
        baseObject.Children[0].Children = new List<Node>() { aSubChild };
    
        // Serialize
    
        XmlWriter writer = XmlWriter.Create("test.xml");
    
        writer.WriteStartDocument();
    
    
        RecursivelySerialize(ref writer, baseObject);
        writer.Flush();
    }
    

    It calls a method called RecursivelySerialize, which does that actual work:

    private static void RecursivelySerialize(ref XmlWriter writer, Node sc) {
        writer.WriteStartElement("Node");
    
        writer.WriteElementString("SomeProperty", sc.SomeProperty);
    
        if (sc.Children.Count > 0) {
            writer.WriteStartElement("Nodes");
    
            foreach (Node scChild in sc.Children)
                RecursivelySerialize(ref writer, scChild);
    
            writer.WriteEndElement();
        }
    
        writer.WriteEndElement();
    }
    

    This method isn’t complex. To improve it, you could use Reflection to dynamically serialize any type of class. Here is the output I got (formatted nicely) when running the above code:

    <?xml version="1.0" encoding="utf-8"?>
    <Node>
        <SomeProperty>This is the base class</SomeProperty>
        <Nodes>
            <Node>
                <SomeProperty>This is a child</SomeProperty>
                    <Nodes>
                        <Node>
                            <SomeProperty>This is a child of a child</SomeProperty>
                        </Node>
                    </Nodes>
            </Node>
            <Node>
                <SomeProperty>This is another child</SomeProperty>
            </Node>
        </Nodes>
    </Node>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.