Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

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

This sample illustrates how to read an XML Schema Definition language (XSD) file into the Schema Object Model (SOM). Then, the sample writes the XSD schema which has been loaded into memory to a StringWriter for display to the screen. The schema could also be written to a file using an XmlWriter.

This SOM provides a set of classes which directly reflect the World Wide Web Consortium (W3C) XSD specification. The classes, methods, and properties of XmlSchema provide the ability to create an in-memory version of the schema that can be complied and used in validation through XmlSchemaSet.

XmlSchema can load and save valid XML Schemas. It also has strongly typed classes which can be used to create in-memory schemas. For validation purposes, XmlSchema can be used by the XmlSchemaSet and XmlReader classes.

VB XmlReadWriteSchema.exe
View Source
[This sample can be found at C:\DevFusion.Data\legacy\quickstart.developerfusion.co.uk\QuickStart\howto\samples\Xml\XmlReadWriteSchema\]

Typically, you use the XmlSchema if you need to load and/or create a valid schema. This sample simply loads a simple schema from a file.

XmlSchema mySchema = XmlSchema.Read(XmlReader.Create(args), null);

Once loaded, the sample writes the schema to a StringWriter and displays the StringWriter on the screen.



  1. The Schema Object Model (SOM) provides a navigatable set of classes which directly reflect the W3C XSD specification.
  2. A SOM is built for each of the imported and included schemas and these are held in the includes collection
  3. The items collection is a list of all the schema element types at the schema level from the loaded schema. This is used for persistence.
  4. Hashtables from Elements, Attributes, and so on, are built which reference all the schema element types at the schema level for all referenced schemas (that is, those in the includes collection), as well as this one. This provides an easy lookup mechanism on the element name.

Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.