Within Visual Studio include the XSD within your project and right click the "Generate Data Binding Code" menu item.
The code generation is highly configurable, but we will use all the defaults.
The generated class library is automatically re-generated when you change the settings or alter the schema.
You have now generated an XML Data Model from your XML Schema (XSD).
The following changes will have been made to your project:-
A nested .cs file which contains the generated code.
Liquid XML Objects settings in the 'Properties' window when you select the XSD in the 'Solution Explorer'
A folder containing the compressed XSD schemas as embedded resources. See XSD Validation
The addition of the NuGet package LiquidTechnologies.XmlObjects.Runtime, and a reference to System.Numerics
Changes to the schema or any of the Liquid XML Objects settings will cause the code to be re-generated.
You can also use this approach when dealing with schemas held in multiple files that can be accessed via 1 root schema (i.e. the root schema includes all the other schema files it needs). Note: In this case changes to the related schemas will not cause the code to be automatically re-generated.
Generating Code from a single XSD | Generating code from a Schema Set |
---|---|
All the child schemas are included from a single root schema 'A'. 'A' should be added to the Visual Studio project, and code generated from it. If the schema files 'B' and 'C' are local then It is recommended that they are added to the project. You should not generate code from 'B' or 'C' within the project. If all your schema files are remote our outside of the project you could also use a schema set. |
If multiple schemas need to be added in order to create a set, then you should create a schema set, and generate code from this. The schema set must contain 'A' and 'D', the schemas 'B' and 'C' can be added, but its not required. Schema Sets make it possible to work with multiple different schemas in the same project or where the schemas are structured in this way. |