Read/write Architecture
This example illustrates how to read the XML Schema Definition Language (XSD) file to the schema object model (SOM. This example then writes the XSD Schema that has been loaded into the memory to stringwriter to display it on the screen. You can also use xmlwriter to write the schema to a file.
The SOM provides a set of classes that directly reflect the W3C XSD specifications. The classes, methods, and attributes of XMLSCHEMA can be used to create an in-memory version of the schema. The schema version can be compiled through xmlschemacollection and used for verification.
XMLSCHEMA can load and save valid XSD architectures. It also has a strongly typed class that can be used to create an in-memory architecture. For verification, xmlschemacollection and xmlvalidatingreader classes can use XMLSCHEMA.
|
VB xmlreadwriteschema. aspx |
[Running example] | [View Source Code] |
You can use XMLSCHEMA to load and/or create a valid schema. In this example, only one simple architecture is loaded from the file.
private const String document = "sample.xsd"; ... XmlSchema mySchema = XmlSchema.Read(new XmlTextReader(document)); private const document as String = "sample.xsd" ... Dim mySchema as XmlSchema = XmlSchema.Read(new XmlTextReader(document)) |
C # |
VB |
|
After loading, this example writes the schema to stringwriter and displays the stringwriter on the screen.
mySchema.Write(myXmlWriter); Console.WriteLine(myStringWriter.ToString()); mySchema.Write(myXmlWriter) Console.WriteLine(myStringWriter.ToString()) |
C # |
VB |
|
Summary
- The schema object model (SOM) provides a set of browsed classes that directly reflect W3C XSD specifications.
- Som is created for each imported and contained architecture, which is retained in the inclusion set.
- An item set is a list of all schema element types at the architecture level in the loaded architecture. This list can be used continuously.
- In addition to this list, it also provides hash tables for all elements, attributes, and other elements generated by referenced architectures (that is, those in the contained architecture, these tables reference All Schema element types at the schema level. This provides a convenient mechanism for searching element names.