- Notifications
You must be signed in to change notification settings - Fork0
Yet Another XML Serialization Library for the .NET Framework and .NET Core
License
sinairv/YAXLib
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
NOTE: This is a fork of the main YAXLib repository and might be out of date. Please refer to the main YAXLib repository for the most recent code and discussions:https://github.com/YAXLib/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 makesYAXLib 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.,
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
, andSystem.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.
In the first place please have a look at theYAXLib Wiki. It is a good source to start.The next best documentation forYAXLib 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 toYAXLibTests
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.
To installYAXLib, run the following command in thePackage Manager Console:
PM> Install-Package YAXLib
Imagine that we have a simpleWarehouse
class with the following definition:
publicclassWarehouse{publicclassPerson{publicstringSSN{get;set;}publicstringName{get;set;}publicstringFamily{get;set;}publicintAge{get;set;}}publicstringName{get;set;}publicstringAddress{get;set;}publicdoubleArea{get;set;}publicList<string>Items{get;set;}publicDictionary<string,int>ItemQuantitiesDic{get;set;}publicPersonOwner{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 ourWarehouse
class:
<Warehouse> <Name>Foo Warehousing Ltd.</Name> <Address>No. 10, Some Ave., Some City, Some Country</Address> <Area>120000.5</Area> <Items> <String>Bicycle</String> <String>Football</String> <String>Shoe</String> <String>Treadmill</String> </Items> <ItemQuantitiesDic> <KeyValuePairOfStringInt32> <Key>Bicycle</Key> <Value>10</Value> </KeyValuePairOfStringInt32> <KeyValuePairOfStringInt32> <Key>Football</Key> <Value>120</Value> </KeyValuePairOfStringInt32> <KeyValuePairOfStringInt32> <Key>Shoe</Key> <Value>600</Value> </KeyValuePairOfStringInt32> <KeyValuePairOfStringInt32> <Key>treadmill</Key> <Value>25</Value> </KeyValuePairOfStringInt32> </ItemQuantitiesDic> <Owner> <SSN>123456789</SSN> <Name>John</Name> <Family>Doe</Family> <Age>50</Age> </Owner></Warehouse>
It's good to have it serialized this simple, butYAXLib 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 ourWarehouse
class with the followingYAXLib attributes and see the XML result.
[YAXComment("Watch it closely. It's awesome, isn't it!")]publicclassWarehouse{publicclassPerson{[YAXAttributeFor("..")][YAXSerializeAs("OwnerSSN")]publicstringSSN{get;set;}[YAXAttributeFor("Identification")]publicstringName{get;set;}[YAXAttributeFor("Identification")]publicstringFamily{get;set;}publicintAge{get;set;}}[YAXAttributeForClass]publicstringName{get;set;}[YAXSerializeAs("address")][YAXAttributeFor("SiteInfo")]publicstringAddress{get;set;}[YAXSerializeAs("SurfaceArea")][YAXElementFor("SiteInfo")]publicdoubleArea{get;set;}[YAXCollection(YAXCollectionSerializationTypes.Serially,SeparateBy=", ")][YAXSerializeAs("AvailableItems")]publicList<string>Items{get;set;}[YAXDictionary(EachPairName="ItemInfo",KeyName="Item",ValueName="Count",SerializeKeyAs=YAXNodeTypes.Attribute,SerializeValueAs=YAXNodeTypes.Attribute)][YAXCollection(YAXCollectionSerializationTypes.RecursiveWithNoContainingElement)][YAXSerializeAs("ItemQuantities")]publicDictionary<string,int>ItemQuantitiesDic{get;set;}publicPersonOwner{get;set;}}
And this is the result of XML serialization:
<!-- Watch it closely. It's awesome, isn't it!--><WarehouseName="Foo Warehousing Ltd."OwnerSSN="123456789"> <SiteInfoaddress="No. 10, Some Ave., Some City, Some Country"> <SurfaceArea>120000.5</SurfaceArea> </SiteInfo> <AvailableItems>Bicycle, Football, Shoe, Treadmill</AvailableItems> <ItemInfoItem="Bicycle"Count="10" /> <ItemInfoItem="Football"Count="120" /> <ItemInfoItem="Shoe"Count="600" /> <ItemInfoItem="treadmill"Count="25" /> <Owner> <IdentificationName="John"Family="Doe" /> <Age>50</Age> </Owner></Warehouse>
- Sina Iravanian
- Julian Verdurmen
- axuno gGmbH
- and many others. SeeChange Log for the list of all the people who kindly contributed to YAXLib.
Logo designed byaxuno gGmbH
Copyright (c) 2009 - 2021 Sina Iravanian, Julian Verdurmen, axuno gGmbH and other contributors - Licenced underMIT
About
Yet Another XML Serialization Library for the .NET Framework and .NET Core
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Languages
- C#100.0%