https://github.com/yaxlib/yaxlib
Yet Another XML Serialization Library for the .NET Framework and .NET Core
https://github.com/yaxlib/yaxlib
deserialization dot-net dot-net-core serialization serialization-library xml-serialization
Last synced: 12 months ago
JSON representation
Yet Another XML Serialization Library for the .NET Framework and .NET Core
- Host: GitHub
- URL: https://github.com/yaxlib/yaxlib
- Owner: YAXLib
- License: mit
- Created: 2012-05-08T12:16:54.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2025-03-14T08:33:42.000Z (about 1 year ago)
- Last Synced: 2025-04-03T12:06:54.317Z (about 1 year ago)
- Topics: deserialization, dot-net, dot-net-core, serialization, serialization-library, xml-serialization
- Language: C#
- Homepage:
- Size: 3.23 MB
- Stars: 170
- Watchers: 14
- Forks: 41
- Open Issues: 12
-
Metadata Files:
- Readme: ReadMe.md
- Changelog: ChangeLog.md
- License: LICENSE.txt
Awesome Lists containing this project
README

# YAXLib: Yet Another XML Serialization Library
[](https://ci.appveyor.com/project/yaxlib/yaxlib/branch/master)
[](https://ci.appveyor.com/project/yaxlib/yaxlib/branch/master)
[](https://sonarcloud.io/summary/new_code?id=yaxlib_YAXLib)
[](https://sonarcloud.io/summary/new_code?id=yaxlib_YAXLib)
[](https://www.nuget.org/packages/YAXLib/)
## Project Status: Looking for contributors and maintainers
We need your help with this project. If you like it, and you are familiar with XML or are willing to help and learn, you can take on different tasks and open pull requests.
We will continue to provide support for current users and publish bug fix releases as far as time allows.
## About YAXLib
*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.
## Features
* Allowing the programmer to format the XML result as desired
* Support for specifying path-like serialization addresses, e.g., `elem1/elem2/elem3`, and `../elem1`, and `./elem1`
* Support for XML namespaces
* Serialization and deserialization of all known generic and non-generic collection classes in `System.Collections`, and `System.Collections.Generic`
* 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.
## Documentation
In the first place please have a look at the [YAXLib Wiki](https://github.com/YAXLib/YAXLib/wiki). It is a good source to start.
The next best documentation for *YAXLib* is its various samples and unit-tests in this repo.
To play with sample classes, open one of the solution files in Visual Studio, go to `YAXLibTests` project, `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.
## Nuget
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:
```csharp
public class Warehouse
{
public class Person
{
public string SSN { get; set; }
public string Name { get; set; }
public string Family { get; set; }
public int Age { get; set; }
}
public string Name { get; set; }
public string Address { get; set; }
public double Area { get; set; }
public List Items { get; set; }
public Dictionary ItemQuantitiesDic { get; set; }
public Person Owner { get; set; }
}
```
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 `Warehouse` class:
```xml
Foo Warehousing Ltd.
No. 10, Some Ave., Some City, Some Country
120000.5
Bicycle
Football
Shoe
Treadmill
Bicycle
10
Football
120
Shoe
600
treadmill
25
123456789
John
Doe
50
```
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.
```csharp
[YAXComment("Watch it closely. It's awesome, isn't it!")]
public class Warehouse
{
public class Person
{
[YAXAttributeFor("..")]
[YAXSerializeAs("OwnerSSN")]
public string SSN { get; set; }
[YAXAttributeFor("Identification")]
public string Name { get; set; }
[YAXAttributeFor("Identification")]
public string Family { get; set; }
public int Age { get; set; }
}
[YAXAttributeForClass]
public string Name { get; set; }
[YAXSerializeAs("address")]
[YAXAttributeFor("SiteInfo")]
public string Address { get; set; }
[YAXSerializeAs("SurfaceArea")]
[YAXElementFor("SiteInfo")]
public double Area { get; set; }
[YAXCollection(YAXCollectionSerializationTypes.Serially, SeparateBy = ", ")]
[YAXSerializeAs("AvailableItems")]
public List Items { get; set; }
[YAXDictionary(EachPairName = "ItemInfo", KeyName = "Item", ValueName = "Count",
SerializeKeyAs = YAXNodeTypes.Attribute,
SerializeValueAs = YAXNodeTypes.Attribute)]
[YAXCollection(YAXCollectionSerializationTypes.RecursiveWithNoContainingElement)]
[YAXSerializeAs("ItemQuantities")]
public Dictionary ItemQuantitiesDic { get; set; }
public Person Owner { get; set; }
}
```
And this is the result of XML serialization:
```xml
120000.5
Bicycle, Football, Shoe, Treadmill
50
```
**And even more: You can deserialize this `XML` back to an instance of the `Warehouse` class.**
## Contributors
* [Sina Iravanian](https://github.com/sinairv)
* [Julian Verdurmen](https://github.com/304NotModified)
* [axuno gGmbH](https://github.com/axuno)
* and many others. See [Change Log](https://github.com/YAXLib/YAXLib/blob/master/ChangeLog.md) for the list of all the people who kindly contributed to YAXLib.
## Logo
Logo designed by [axuno gGmbH](https://github.com/axuno)
## License
Copyright (c) 2009 - 2021 Sina Iravanian, Julian Verdurmen, axuno gGmbH and other contributors - Licenced under [MIT](LICENSE.txt)