Click here to Skip to main content
15,891,951 members
Articles / Programming Languages / XML

Yet Another XML Serialization Library for the .NET Framework

Rate me:
Please Sign up or sign in to vote.
4.92/5 (91 votes)
2 Oct 2012MIT24 min read 516K   207  
A flexible XML serialization library that lets developers design the XML file structure, and select the exception handling policy. YAXLib supports polymorphic serialization and serializing generic and non-generic collection classes and arrays.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAXLib;

namespace DemoApplication.SampleClasses
{
    [YAXSerializeAs("Pricing")]
    public class Request
    {
        public Request()
        { }

        [YAXAttributeForClass()]
        public string id { get; set; }

        [YAXAttributeFor("version")]
        public string major { get; set; }

        [YAXAttributeFor("version")]
        public string minor { get; set; }

        [YAXSerializeAs("value_date")]
        [YAXElementFor("input")]
        public string valueDate { get; set; }

        [YAXSerializeAs("storage_date")]
        [YAXElementFor("input")]
        public string storageDate { get; set; }

        [YAXSerializeAs("user")]
        [YAXElementFor("input")]
        public string user { get; set; }

        //[YAXElementFor("input")]
        //public string skylab_config { get; set; }

        //[YAXElementFor("skylab_config")]
        //public string job { get; set; }

        [YAXElementFor("input")]
        [YAXSerializeAs("skylab_config")]
        public SkyLabConfig Config { get; set; }

        internal static Request GetSampleInstance()
        {
            return new Request()
            {
                id = "123",
                major = "1",
                minor = "0",
                valueDate = "2010-10-5",
                storageDate = "2010-10-5",
                user = "me",
                Config = new SkyLabConfig() { Config = "someconf", Job = "test" }
            };
        }

        public override string ToString()
        {
            return GeneralToStringProvider.GeneralToString(this);
        }
    }

    public class SkyLabConfig
    {
        [YAXSerializeAs("SomeString")]
        public string Config { get; set; }

        [YAXSerializeAs("job")]
        public string Job { get; set; }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Australia Australia
A software designer and developer

Comments and Discussions