Creating XML Schemas from XML Files
You create schemas based on existing XML files when you want to validate that other XML files conform to the same data structure and data type restrictions as the original XML file.
Tip To create an ADO.NET dataset from an XML file, you must first create a schema and then generate a dataset from that schema. For more information, see Creating ADO.NET Typed Datasets from Schemas.
Note There are some instances of XML documents that schemas and datasets cannot be created from. Although the XML would be considered well formed, trying to create a schema will generate a Failed to Create Schema error if the contents cannot be logically interpreted into structured data.
To create a new XML Schema based on an existing XML Document
- Load an XML document (.xml file) into the XML Designer.
- From the XML menu click Create Schema.
An XML Schema (.xsd file) is added to the current project with the same name as the original XML file.
- Load the newly created XML Schema (.xsd file) into the XML Designer.
- Verify and edit the data types that were assigned when creating the schema.
Note When a schema is inferred from an existing XML document, all the data types are initially set to string, so you must edit the data types according to the content requirements of your XML data.
- If you need to make changes to the schema, you can use the XML Designer to add, edit, and remove elements.
- If the schema you just created requires primary or unique keys defined then you should create those now. For more information, see Creating Primary and Unique Keys in XML Schemas.
- If the schema you just created requires relationships defined between tables then you should create those now. For more information, see Creating DataRelation Objects with the XML Designer.
- Since the XML Designer can create datasets based on the structure of existing XML Schemas, you can now generate a new dataset based on the schema you created in the previous steps. For more information, see Creating ADO.NET Typed Datasets from Schemas.
XML Files | Creating New XML Files | Assigning Schemas to XML Files | Checking for Well-Formed and Valid XML | Relational Data in XML Schemas | Creating XML Schemas and Datasets | Introduction to Data Access with ADO.NET | Introduction to Datasets