XML Schema is the recommended choice for the consortium, which provides tools for defining the structure, content, and semantics of XML files. XML schemas have two key advantages over the other two schema modeling tool file type definitions (DTDs) and XDR (XML Data reduced). First, because it is an official recommendation of the Consortium for the definition of XML data structures, the same definition is used by corporate organizations. Second, it is the latest schema technology, so its construction is to fix the vulnerabilities and flaws in the other two, especially in the DTD.
XDR is not an alternative to schema technology because it is just an early draft of Microsoft's XML Schema specification. In. NET, XDR is primarily supported for backward compatibility. SQL Server 2000 's XML extensions and Microsoft's COM parser (MSXML) are still widely used.
Let's start by looking at how the XML Schema Object model is made available to you. NET class to manipulate the schema part. Then, let's take a look at several ways to deal with schema information.
Schema background
XML schemas represent XML type systems and should be used to describe classes and objects when they serialize their state to other applications and platforms. The. NET XML Schema Object Model (SOM) can help in. Building a bridge between the Net-specific type system and the XML Schema type system makes it easy to create and modify schemas in a planned way. The schema file is an XML file with an. xsd extension.
All of the data types that can be used in an XML schema file have one. NET copy. Once an XSD schema is compiled as. NET presentation (representation) object model, you can use the SOM class to access them. The schema compiler assembles XSD into a XmlSchema object that displays information about the schema through its properties and methods.
On a given platform, an effective serialization mechanism between XSD and a synthetic binary class provides tremendous potential, which is a critical step towards full cross-platform interoperability implementation. In. NET, XML serialization is accomplished by XmlSerializer classes and leveraging the XML Schema Definition tool (Xsd.exe) service. This tool is a binary executable in the. NET Framework SDK, which you will find in the bin subdirectory of the. NET Framework installation path, typically C:Program FilesMicrosoft Visual Studio. Netframeworksdk.
Xsd.exe can generate a C # or Visual Basic class from an XSD file and infer an XML schema from an XML source file. This tool is also responsible for visual Studio. NET executes a schema-related technology in XML.
Check som
The. NET Framework provides a class hierarchy to edit an existing schema or create a new schema from scratch. The class is defined in the System.Xml.Schema namespace, and the root class in the namespace is XmlSchema. Once the application retains an instance of a class, they can load an existing XSD file and use the contained information to form internal properties and collections, and by using the XmlSchema programming interface, you can add or edit elements, attributes, and other schema parts. Finally, the class provides a write method that allows you to save current content for a valid stream object.
There are two ways to create an instance of a XmlSchema class: You can use the default constructor, it will return an instance of a new empty class, or you can use the static Read method.
The Read method runs through a stream, a text reader, or an XML reader on the available schema information, and the returned schema has not been compiled. The Read method accepts a second argument, which is a validation event handler. You can set this argument to NULL, but you cannot find and handle validation errors in the read schema. Table A shows how to use the. NET som to read and compile a schema.
Once the schema is compiled, you can access the constituent elements of the schema defined by the Post-Schema validation Information group, and you need to use the SchemaTypes collection to access the actual types in the schema.