AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Use the Xml Schema Object Model?

This sample illustrates how to read two XML Schema Definition language (XSD) schemas into a SchemaSet and navigate through the schemas that they represent.

This sample shows how to use the XmlSchemaSet to cache and retrieve multiple schemas, and demonstrates that the Schema Object Model (SOM) loads and saves valid XML Schemas. You can also use the SOM to create in-memory schemas by using strongly-typed classes.

To demonstrate how to navigate the SOM, this sample outputs a formatted version of the two XML Schemas that were loaded into the XmlSchemaSet.

VB XmlSchemaObjectModel.exe
View Source

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Xml\XmlSchemaObjectModel\
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.]

This sample first creates an XmlWriter that eventually writes out to the screen. The sample does this to take advantage of the various methods of the XmlWriter that produce well-formed XML. Some examples of these methods are the WriteStartElement, WriteEndElement, and WriteAttributeString. Then, the sample creates an XmlNameTable and adds the name table to the XmlSchemaSet. The sample adds two unique XML Schemas into the XmlSchemaSet and compiles the schemas. Finally, the sample writes each schema in the XmlSchemaSet to the screen.


Dim settings As New XmlWriterSettings()
settings.Indent = True
settings.ConformanceLevel = ConformanceLevel.Fragment
writer = XmlWriter.Create(Console.Out, settings)
...
Dim xmlNameTable As NameTable = New NameTable()
Dim xmlSchemaSet As New XmlSchemaSet(xmlNameTable)
xmlSchemaSet.Add(Nothing, sampleSchema1)
xmlSchemaSet.Add(Nothing, sampleSchema2)
xmlSchemaSet.Compile()
...
Dim tempXmlSchema As XmlSchema
For Each tempXmlSchema In xmlSchemaSet.Schemas()
    ' Write out the various schema parts
    WriteXSDSchema()
Next tempXmlSchema
VB

The WriteXSDSchema function loops through each item in the XmlSchema and, after determining its type, formats the item for output to the screen.

Summary

  1. The Schema Object Model (SOM) loads and saves valid XML Schemas.
  2. The SOM provides an easy way to create in-memory schemas using strongly typed classes.
  3. You can use the XmlSchemaSet object to cache and retrieve multiple schemas.




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


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.