Microsoft KB Archive/313826

From BetaArchive Wiki

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

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:

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:

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

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.

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

Microsoft Knowledge Base Articles

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:

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

REFERENCES

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

313651 INFO: Roadmap for XML in the .NET Framework


back to the top

Keywords: kbarttyperoadmap kbinfo KB313826