Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   |   Class Browser
  |   I want my samples in...   

How Do I...? Common Tasks QuickStart Tutorial

Go To...

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.

C# XmlReadWriteSchema.exe
View Source

[This sample can be found at M:\web\users\Sites\AspnetQuickStart\v2.0\QuickStart\howto\samples\Xml\XmlReadWriteSchema\
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]

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

		
XmlSchema schema = XmlSchema.Read(XmlReader.Create(document), null);
C#

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

		
schema.Write(writer);
C#

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.


Hosted by MaximumASP | Found a broken link? | Contact Us | Terms and conditions | Privacy Policy | Advertise with us
� 2000 - 2008  Mindcracker LLC. All Rights Reserved