Page view counter

These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.

 

 

   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   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 that has been loaded into memory to a StringWriter for display to the screen. The schema could also be written to a file by using an XmlWriter.

This SOM provides a set of classes that 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 that 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

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

		
Dim schema as XmlSchema  = XmlSchema.Read(XmlReader.Create(document),Nothing)
VB

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

		
schema.Write(writer)
VB

Summary

  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, 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 � 2005 Microsoft Corporation. All rights reserved.