1

My program generates some numeric results which are held together in a class:

[Serializable]
public class Examination
{

    public string _examiner { get; set; }
    public string _interpretation { get; set; }
    DateTime _examination_date { get; set; }

    // two following properties about 100x100 in size
    public Point3D[,] _surface_coordinates { get; set; }
    public double [,] _mapa_curvatura { get; set; }

    public Point3DCollection _symmetry_line { get; set; }
}

Now I want to persist this using serialization (no need for ORM/Database in principle), and I am having some doubts:

  1. I need the serialized data to be accessible to scripts in other languages (Python mostly) so I wouldn't use Binary Serialization, using XmlSerialization instead;
  2. Multidimensional data is not supported, so I had to convert [,] arrays to [][] arrays, which looked a bit "dirty" to me (not big deal, though, if that were the only matter);
  3. The resulting XML is a bit too big (2Mb per file), while I was getting results a lot smaller with quick'n'dirty binary formats in python (for example, saving array of doubles to a long string, putting rows and columns in the filename itself, then parsing it and reshaping during deserialization: not pretty too!).

Since I am a complete beginner in the Serialization field, I would like to ask: "Which would be an adviseable strategy/tactic to serialize and deserialize this class to disk?" Primary requirements would be:

  • Readable in other languages;
  • Compact file size;
  • Respecting C#/.NET good-practices and common idioms;

Thanks for reading!

5
  • 1
    Less verbose than XML and still readable is JSON. Commented Oct 7, 2013 at 18:07
  • 1
    Why is 2MB too big? What are the size requirements, and where are they coming from? Commented Oct 7, 2013 at 18:08
  • @PrestonGuillot too big because there would eventually be a lot of 2mb files, and I know that the numeric structure is much smaller than its (rather verbose/inflated/reduntant) XML representation. As other suggested, GZipping it might be an acceptable solution, what do you think? Commented Oct 7, 2013 at 18:13
  • (@PrestonGuillot actually I would go straight with Binary Serialization if its structure was at least machine-readable in other languages) Commented Oct 7, 2013 at 18:14
  • The concern of compressing the serialized document is somewhat orthogonal to the serialized document being interop friendly. Depending on your need, it may be a completely viable option. It definitely isn't something that I'd consider a non-idiomatic concept because of C# or .Net, it just becomes part of your spec. If you want to control some aspects of the serialized XML itself, this is also possible (e.g. a field named "ThisIsAHugeNameToRepeat" can be serialized with a name of "x" if you really want: msdn.microsoft.com/en-us/library/2baksw0z.aspx). Commented Oct 7, 2013 at 18:20

1 Answer 1

2

Readable in other languages

This is one of the reasons XML was designed, personally I would stick with it.

Compact file size

Have you considered storing it as a compressed file? e.g. MyXml.zip.

Respecting C#/.NET good-practises and common idioms

Just stick to the docs and you should be fine.

Sign up to request clarification or add additional context in comments.

3 Comments

I have considered using GZipStream to zip the XML, but was wondering if that would be considered idiomatic / good-practice in C#...
@heltonbiker why do you think it wouldn't be? You will probably find that the majority of systems that use an open XML format actually use archiving for this very reason. For example, take any office file that uses XML e.g. .xlsx rename it to .zip and open it.
I am currently saving it as "myFile.xml.gz", using GZipStream. The double extension is used so that the xml file inside the gz file has the proper extension. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.