XmlSchemaInference Classe
Definição
Infere uma esquema de Linguagem de Definição de Esquema XML (XSD) de um documento XML.Infers an XML Schema Definition Language (XSD) schema from an XML document. A classe XmlSchemaInference não pode ser herdada.The XmlSchemaInference class cannot be inherited.
public ref class XmlSchemaInference sealed
public sealed class XmlSchemaInference
type XmlSchemaInference = class
Public NotInheritable Class XmlSchemaInference
- Herança
-
XmlSchemaInference
Exemplos
Este exemplo usa um arquivo XML como entrada e gera um esquema que pode validar o XML de exemplo.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);
}
XmlReader reader = XmlReader.Create("contosoBooks.xml");
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchemaInference schema = new XmlSchemaInference();
schemaSet = schema.InferSchema(reader);
foreach (XmlSchema s in schemaSet.Schemas())
{
s.Write(Console.Out);
}
Dim reader As XmlReader = XmlReader.Create("contosoBooks.xml")
Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
Dim schema As XmlSchemaInference = New XmlSchemaInference()
schemaSet = schema.InferSchema(reader)
For Each s As XmlSchema In schemaSet.Schemas()
s.Write(Console.Out)
Next
Este é o arquivo XML de entrada.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>
O esquema a seguir é inferido do documento XML.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>
Comentários
Importante
- Não use esquemas de fontes ou locais desconhecidos ou não confiáveis.Do not use schemas from unknown or untrusted sources or locations. Isso irá comprometer a segurança do seu código.Doing so will compromise the security of your code.
- Esquemas XML (incluindo esquemas embutidos) são inerentemente vulneráveis a ataques de negação de serviço; Não os aceite em cenários não confiáveis.XML schemas (including inline schemas) are inherently vulnerable to denial of service attacks; do not accept them in untrusted scenarios.
- Mensagens de erro de validação de esquema e exceções podem expor informações confidenciais sobre o modelo de conteúdo ou caminhos de URI para o arquivo de esquema.Schema validation error messages and exceptions may expose sensitive information about the content model or URI paths to the schema file. Tenha cuidado para não expor essas informações a chamadores não confiáveis.Be careful not to expose this information to untrusted callers.
A XmlSchemaInference classe no System.Xml.Schema namespace permite que você inferir um esquema XSD (linguagem de definição de esquema XML) da estrutura de um documento XML.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. A saída de classe de XmlSchemaInference um esquema XML que pode validar o documento XML.The XmlSchemaInference class outputs an XML schema that can validate the XML document.
A XmlSchemaInference classe dá suporte aos padrões W3C XML e esquemas XML.The XmlSchemaInference class supports the W3C XML and XML Schemas standards. Ele pode ser usado para inferir um novo esquema ou para refinar um esquema existente.It can be used to infer a new schema or to refine an existing schema.
Construtores
| XmlSchemaInference() |
Inicializa uma nova instância da classe XmlSchemaInference.Initializes a new instance of the XmlSchemaInference class. |
Propriedades
| Occurrence |
Obtém ou define o valor de XmlSchemaInference.InferenceOption que afeta as declarações de ocorrência de esquema deduzidas do documento XML.Gets or sets the XmlSchemaInference.InferenceOption value that affects schema occurrence declarations inferred from the XML document. |
| TypeInference |
Obtém ou define o valor de XmlSchemaInference.InferenceOption que afeta os tipos deduzidos do documento XML.Gets or sets the XmlSchemaInference.InferenceOption value that affects types inferred from the XML document. |
Métodos
| Equals(Object) |
Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object. (Herdado de Object) |
| GetHashCode() |
Serve como a função de hash padrão.Serves as the default hash function. (Herdado de Object) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
| InferSchema(XmlReader) |
Deduz um esquema XSD (linguagem de definição de esquema XML) do documento XML contido no objeto XmlReader especificado.Infers an XML Schema Definition Language (XSD) schema from the XML document contained in the XmlReader object specified. |
| InferSchema(XmlReader, XmlSchemaSet) |
Deduz um esquema XSD (linguagem de definição de esquema XML) do documento XML contido no objeto XmlReader especificado e refina o esquema deduzido usando um esquema existente no objeto XmlSchemaSet especificado com o mesmo namespace de destino.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. |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |