Liquid XML Data Binder 2019
Generating an XML Data Model from an XSD in Visual Studio
Liquid XML Objects (C#, Visual Basic .Net) > Code Generation > Visual Studio > Generating an XML Data Model from an XSD in Visual Studio

Generating code from an XSD

  1. Within Visual Studio include the XSD within your project and right click the "Generate Data Binding Code" menu item.

  2. The code generation is highly configurable, but we will use all the defaults.

  3. The generated class library is automatically re-generated when you change the settings or alter the schema.

If you need to load multiple schema files that have no common root then you can use a schema set, see Generating an XML Data Model from a Schema Set in Visual Studio.

You have now generated an XML Data Model from your XML Schema (XSD).

The following changes will have been made to your project:-

  1. A nested .cs file which contains the generated code.

  2. Liquid XML Objects settings in the 'Properties' window when you select the XSD in the 'Solution Explorer'

  3. A folder containing the compressed XSD schemas as embedded resources. See XSD Validation

  4. 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.

See Manually Forcing Code Generation

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.

See Also

Generated Code