YAXLib is a flexible XML serialization library that lets developers design freely the XML file structure, choose among private and public fields to be serialized, and serialize all known collection classes and arrays (single-dimensional, multi-dimensional, and jagged arrays) in the .NET Framework.
YAXLib can be used as a powerful XML parser or generator, that exploits the object to XML mapping in the class definitions themselves.
The exception handling policies and its missing data recovery capabilities makes YAXLib a reliable tool for XML configuration storage and retrieval.
- Allowing the programmer to format the XML result as desired
- Support for specifying path-like serialization addresses, e.g.,
- Support for XML namespaces
- Serialization and deserialization of all known generic and non-generic collection classes in
- Support for serialization of single-dimensional, multi-dimensional, and jagged arrays
- Support for recursive serialization of collections (i.e., collection of collections)
- Support for specifying aliases for enum members
- Support for defining user-defined custom serializer for specific types or specific fields
- Allowing the programmer to choose the fields to serialize (public, or non-public properties, or member variables)
- Support for serialization and deserialization of objects through a reference to their base-class or interface (also known as polymorphic serialization)
- Support for multi-stage deserialization
- Allowing the programmer to add comments for the elements in the XML result
- and more …
See the accompanied demo application for an example of each functionality.
The best documentation for YAXLib is its various samples and unit-tests. However this (rather old) CodeProject article is a good source to start. The article is also found in the
Doc folder of the source code.
To play with sample classes, open one of the solution files (based on version of your Visual Studio), go to
SampleClasses folder. If you want a sample class to appear in the demo application simply put a
[ShowInDemoApplication] attribute on top of the class definition. In the demo application you can see the serialization result, modify it, and test its deserialization.
To install YAXLib, run the following command in the Package Manager Console:
PM> Install-Package YAXLib
A Quick Introduction
Imagine that we have a simple
Warehouse class with the following definition:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Without adding any attributes, YAXLib is perfectly capable of serializing objects of the above class. The following is an XML serialization of a sample instantiation of our
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
It’s good to have it serialized this simple, but YAXLib can do more than that. Let’s do some house-keeping on the XML side. Let’s move the XML-elements and attributes around, so that we will have a nicer and more human readable XML file. Let’s decorate our
Warehouse class with the following YAXLib attributes and see the XML result.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
And this is the result of XML serialization:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Copyright (c) 2009 - 2013 Sina Iravanian and Contributors - Licenced under MIT