Liquid XML Objects (C#, Visual Basic .Net) / Using the Generated Code / An Introduction to the Generated Data Model
In This Topic
    An Introduction to the Generated Data Model
    In This Topic

    The Liquid XML Objects code generator creates a very light weight set of classes attributed with meta data to describe the underlying XML structure.

    Code Generation Example

    Consider the following schema

    Sample XML Schema
    Copy Code
    <?xml version="1.0" encoding="utf-8" ?>
    <!--Created with Liquid Studio (https://www.liquid-technologies.com)-->
    <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="Root">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="MyElement" type="xs:boolean" />
                    <xs:element name="MyElementCollection" type="xs:double" minOccurs="0" maxOccurs="unbounded" />
                </xs:sequence>
                <xs:attribute name="MyAttribute" type="xs:int" />
            </xs:complexType>
        </xs:element>
    </xs:schema>
    

    Which produces the following code

    Sample Generated Code
    Copy Code
        public partial class RootElm
        {
            public System.Int32 MyAttribute { get; set; }
            public RootElm.RootSeq Seq { get; set; } = new RootElm.RootSeq();
            public partial class RootSeq
            {
                public System.Boolean MyElement { get; set; }
                public List<System.Double> MyElementCollection { get; } = new List<System.Double>();
            }
        }
    

    The Lx... attributes, qualifying namespaces and comments have been removed for clarity.

    Lets examine this is more details.

    This is a very basic example, but you can see that the generated code mirrors the structure of the XSD very closely, this includes representing the xs:sequence within the model. This makes it possible to provide an extremely accurate representation of the XML data within the class model.

    In some instances the generated sequence classes add clutter when using the code, there are a number of ways to avoid this, see Code Generation Models.

     

    The LxSerializer class is used to serialize and de-serialize the data from the generated classes

     

    See Also