XmlSchemaInference Class
Infers an XML Schema Definition Language (XSD) schema from an XML document. The XmlSchemaInference class cannot be inherited.
Assembly: System.Xml (in System.Xml.dll)
| Name | Description | |
|---|---|---|
![]() | XmlSchemaInference() | Initializes a new instance of the XmlSchemaInference class. |
| Name | Description | |
|---|---|---|
![]() | Occurrence | Gets or sets the XmlSchemaInference::InferenceOption value that affects schema occurrence declarations inferred from the XML document. |
![]() | TypeInference | Gets or sets the XmlSchemaInference::InferenceOption value that affects types inferred from the XML document. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | InferSchema(XmlReader^) | Infers an XML Schema Definition Language (XSD) schema from the XML document contained in the XmlReader object specified. |
![]() | InferSchema(XmlReader^, XmlSchemaSet^) | Infers an XML Schema Definition Language (XSD) schema from the XML document contained in the XmlReader object specified, and refines the inferred schema using an existing schema in the XmlSchemaSet object specified with the same target namespace. |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
Security Note
|
|---|
|
The XmlSchemaInference class in the System.Xml.Schema namespace allows you to infer an XML Schema Definition Language (XSD) schema from the structure of an XML document. The XmlSchemaInference class outputs an XML schema that can validate the XML document.
The XmlSchemaInference class supports the W3C XML and XML Schemas standards. It can be used to infer a new schema or to refine an existing schema.
This example takes an XML file as input, and generates a schema that can validate the example XML.
XmlReader^ reader = XmlReader::Create("contosoBooks.xml"); XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet(); XmlSchemaInference^ schema = gcnew XmlSchemaInference(); schemaSet = schema->InferSchema(reader); for each (XmlSchema^ s in schemaSet->Schemas()) { s->Write(Console::Out); }
The following is the input XML file.
<bookstore xmlns="http://www.contoso.com/books"> <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name>Herman</first-name> <last-name>Melville</last-name> </author> <price>11.99</price> </book> <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6"> <title>The Gorgias</title> <author> <name>Plato</name> </author> <price>9.99</price> </book> </bookstore>
The following is the schema inferred from the XML document.
<?xml version="1.0" encoding="utf-8"?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.contoso.com/books" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="bookstore"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="book"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string" /> <xs:element name="author"> <xs:complexType> <xs:sequence> <xs:element minOccurs="0" name="name" type="xs:string" /> <xs:element minOccurs="0" name="first-name" type="xs:string" /> <xs:element minOccurs="0" name="last-name" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="price" type="xs:decimal" /> </xs:sequence> <xs:attribute name="genre" type="xs:string" use="required" /> <xs:attribute name="publicationdate" type="xs:date" use="required" /> <xs:attribute name="ISBN" type="xs:string" use="required" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Available since 2.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


