Microsoft KB Archive/313826

= INFO: Roadmap for XML Schemas in the .NET Framework =

Article ID: 313826

Article Last Modified on 2/20/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q313826



CONTENTS
 SUMMARY

OverviewKey Concepts and QuickStart Tutorials

System.Xml.Schema Namespace

Microsoft Knowledge Base Articles

Programmatically Create XML Schema DefinitionProgrammatically Create XSD Schema from a DatabaseHandle XmlValidatingReader ErrorsValidate XML Data Against XML SchemasCache SchemasCreate a Key Element by Using the XmlSchemaKey Class

GuidelinesTroubleshooting

 REFERENCES



SUMMARY
This article provides a roadmap to learn about the .NET Framework implementation and support for Extensible Markup Language (XML) schemas. Roadmap articles provide links to useful information, including online documentation, Microsoft Knowledge Base articles, and Microsoft white papers, to help you learn about a Microsoft product or technology.

back to the top

Overview
XML schemas define the structures of XML documents. The structure of an XML document is made up of the name, the cardinality, the data types, and the order of the elements and the attributes of the XML document. XML schemas use XML-based syntax to define XML document structures. XML schemas are frequently used to validate the contents of XML documents to make sure that they follow defined structures.

The XML Schema Definition Language (XSD) is the current World Wide Web Consortium (W3C) specification for XML schemas. XSD is an industry standard that is used to create XML schemas.

For more information about XML schemas in general, see the following W3C tutorial:

XML Schema Part 0: Primer

http://www.w3.org/TR/2000/WD-xmlschema-0-20000922/

For more information about the W3C specifications for the XSD schema structures and data types, see the following W3C Web sites:

XML Schema Part 1: Structures

http://www.w3.org/TR/xmlschema-1/

XML Schema Part 2: Datatypes

http://www.w3.org/TR/xmlschema-2/

The .NET Framework implements full support for XML schemas in accordance with the W3C XML schema specifications for structures and for data types. The System.Xml.Schema .NET Framework namespace implements the .NET Framework classes that collectively implement support for the XML Schema Object Model (SOM).

For more information about the System.Xml.Schema namespace, see the following MSDN Web site:

System.Xml.Schema Namespace

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemXmlSchema.asp

For an overview of the XML Schema Object Model in the .NET Framework, see the following MSDN Web site:

Schema Object Model Overview

http://msdn.microsoft.com/library/en-us/cpguide/html/cpconschemaobjectmodeloverview.asp

back to the top

Key Concepts and QuickStart Tutorials
This section includes documentation about key concepts of XML schemas. Additionally, this section includes references to QuickStart tutorials for more information about the commonly used classes in the System.Xml.Schema namespace.

Data Type Support between XML Schema (XSD) Types and .NET Framework Types

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondatatypesupportbetweenxsdtypesnetframeworktypes.asp

Deterministic and Non-Deterministic Schemas

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconnon-deterministicschema.asp

How Do I...Read and Write a Schema?

http://samples.gotdotnet.com/quickstart/howto/doc/Xml/XmlReadWriteSchema.aspx

How Do I...use the Schema Object Model?

http://samples.gotdotnet.com/quickstart/howto/doc/Xml/XmlSchemaObjectModel.aspx

How Do I...Use XML Schema Collection?

http://samples.gotdotnet.com/quickstart/howto/doc/Xml/SchemaCollection.aspx

back to the top

System.Xml.Schema Namespace
The classes in the System.Xml.Schema .NET Framework namespace collectively implement a Schema Object Model (SOM) that complies with the Wide Web Consortium (W3C) XML Schema recommendation. You can use these classes to read a schema from a file or to programmatically generate and compile a schema that can then be persisted to a file on disk.

The SOM is made up of classes (for example, XmlSchema, XmlSchemaElement, and XmlSchemaComplexType) that correspond directly to the XSD structures (xsd:schema, xsd:element, and xsd:complexType) that are defined in the W3C specifications. The following classes are frequently-used SOM classes that are implemented in the System.Xml.Schema namespace:
 * XmlSchema. This class contains the definition of a schema. This class represents the W3C schema element. All XML Schema Definition Language (XSD) elements are children of the schema element.
 * XmlSchemaElement. This is the class for elements. This class represents the W3C element element.
 * XmlSchemaComplexType. This is the class for complex types. This class defines a complex type that determines the set of attributes and the content of an element. This class represents the W3C complexType element.
 * XmlSchemaSimpleType. This class defines a simple type that determines the information and the constraints for the values of attributes or elements with text-only content. This class represents the W3C simpleType element.

Simple types derive from (by extension or by restriction) existing simple types, which are built-in data types and derived simple types. A simple type cannot contain elements and cannot have attributes.
 * XmlSchemaSequence. This class requires the elements in the group to appear in the specified sequence in the containing element. This class represents the W3C sequence (compositor) element.
 * XmlSchemaParticle. This class is a base class for all particle types. Particle types are typically interchangeable. Particle can be a local element declaration or a reference to a global element declaration (element), a compositor (sequence, choice, or all), a reference to a named content model group (group), or an element wildcard character (any).
 * XmlSchemaXPath. This is the class for XML Path Language (XPath) expressions. This class represents the W3C selector element. The W3C field element is a collection of XmlSchemaXPath classes.

back to the top

Programmatically Create XML Schema Definition
The .NET Framework provides various classes to programmatically generate XML schemas.

For more information about how to generate an XSD schema, see the following MSDN Web site:

XmlSchema Class

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlSchemaXmlSchemaClassTopic.asp

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

317903 HOW TO: Modify an XML Schema by Using System.Xml.Schema Classes in Visual Basic .NET

back to the top

Programmatically Create XSD Schema from a Database
The .NET Framework System.Data namespace includes the DataSet class. DataSet can load both relational and hierarchical data. By using the DataSet class, schema from a database can be retrieved and written as XSD schema.

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

317940 HOW TO: Write an XSD Schema from a Database by Using a DataSet

back to the top

Handle XmlValidatingReader Errors
To handle errors that the XmlValidatingReader class detects as it traverses the XML document, you must declare the ValidationEventHandler delegate.

back to the top

Validate XML Data Against XML Schemas
The XmlValidatingReader class provides support for data validation. You can use this class to validate the XML data in all types of XML schemas: XML Schema Definition Language (XSD) schema, XML-Data Reduced (XDR) schema, and Document Type Definition (DTD). You can use the Schemas property to validate the reader by using schema files that are cached in an XmlSchemaCollection object. The ValidationType property specifies what type of validation the reader performs. If you set the property to ValidationType.None, you create a non-validating reader.

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

307379 HOW TO: Validate an XML Document by Using DTD, XDR, or XSD in Visual C# .NET

317463 HOW TO: Validate XML Fragments Against an XML Schema in Visual Basic .NET

back to the top

Cache Schemas
The XmlSchemaCollection class contains a cache of XML Schema Definition Language (XSD) and XML-Data Reduced (XDR) schemas. Schemas are loaded by using the Add method, at which time the schema is associated with a namespace uniform resource identifier (URI). For XSD schemas, this is typically the targetNamespace property of the schema. Although XmlSchemaCollection stores both XSD schemas and XDR schemas, any method and property that takes or returns an XmlSchema object applies to XSD schemas only.

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

317595 HOW TO: Validate an XML Document by Using Multiple Schemas in Visual Basic .NET

back to the top

Create a Key Element by Using the XmlSchemaKey Class
The XmlSchemaKey class identifies a key constraint. This class represents the World Wide Web Consortium (W3C) key element.

317688 HOW TO: Create a Key Element for an XML Schema

back to the top

Guidelines

 * The classes in the System.Xml.Schema namespace work best with XML schemas. Use these classes to read and to write schemas programmatically.
 * Use an XmlSchemaCollection object to cache schemas that are used frequently to validate XML documents in an instance of an application. You can also use XmlSchemaCollection to cache different schemas when you must validate multiple XML documents against different schemas. In this way, you can use a single XmlSchemaCollection object instance to validate the different XML documents.
 * Write error handling code to catch the XmlSchemaException class when you execute the Read and the Compile methods of the XmlSchema object. This .NET Framework exception class provides specific information about any errors that that are raised while reading or compiling XML schemas.

back to the top

Troubleshooting
If you experience problems, or if you have questions, you can refer to the MSDN newsgroups where you can share your experiences with your peers. You can also use the Microsoft Knowledge Base to search for articles about specific issues.

MSDN Newsgroups

http://msdn.microsoft.com/newsgroups/

Searching the Knowledge Base

http://support.microsoft.com/search

back to the top

