If your new to XML schema's or have just been given XML documents which have no underlying XSD, then it is possible to create an XML Schema that describes your data using the XSD Inferrer.
This uses one or more XML documents, and uses them to construct an XML Schema (XSD). Typically the XSD will need a little tweaking before it is exactly what you want, but it is a good starting point.
There are a number of advantages to using an XML Schema.
- It provides intellisense when editing your XML documents
- It allows stricter validation when editing your XML documents
- Validation can be performed prior to an XML document being consumed, which lowers the amount of error handling required in the consuming application (its more acceptable to make assumptions that element will exist etc, as the schema validation has already guaranteed they do).
- Provides a formal description of your data, this is especially useful when more than one developer/analyst is working on the project.
You can infer an XML Schema by opening up an XML file and selecting the "Infer XML Schema" option ()
Specify the sample XML files that will be used to infer the XSD schema.
The more sample files you have the more accurate the resulting XML Schema.
The second page contains options relating to the inferring process.
The name of the schema that will be produced (there is no need to add the .xsd extension).
If more than 1 schema file needs to be created, then the schema files will be named <Schema Name>1.xsd, <Schema Name>2.xsd etc
The location where your schema file/files will be written.
The encoding that will be applied to your XML Schema (UTF-8 or UTF-16 are the most commonly used, only change this if you understand encoding).
If the Occurrence property is set to Restricted, the first time elements are encountered in the XML document, the schema declaration is inferred as minOccurs="1".
When attributes are encountered, the schema declaration is inferred as use="required". If the Occurrence property is set to Relaxed, element schema declarations are inferred as minOccurs="0", and attribute schema declarations are inferred as use="optional".
Type Inference Option
If the TypeInference property is set to Relaxed, the inferred type of elements and attributes in the XML document with simple content is always xs:string.
If the TypeInference property is set to Restricted, more specific types are inferred, such as xs:date, xs:decimal, xs:unsignedByte, and so on.