XmlSchemaInference.TypeInference Propriedade
Definição
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.
public:
property System::Xml::Schema::XmlSchemaInference::InferenceOption TypeInference { System::Xml::Schema::XmlSchemaInference::InferenceOption get(); void set(System::Xml::Schema::XmlSchemaInference::InferenceOption value); };
public System.Xml.Schema.XmlSchemaInference.InferenceOption TypeInference { get; set; }
member this.TypeInference : System.Xml.Schema.XmlSchemaInference.InferenceOption with get, set
Public Property TypeInference As XmlSchemaInference.InferenceOption
Valor da propriedade
Um objeto XmlSchemaInference.InferenceOption.An XmlSchemaInference.InferenceOption object.
Exemplos
Este exemplo ilustra como a inferência de tipos é afetada pela TypeInference propriedade.This example illustrates how type inference is affected by the TypeInference property. O código de exemplo infere os tipos de um arquivo XML de duas maneiras diferentes: relaxada e restrita.The example code infers types from an XML file in two different ways: relaxed and restricted. Este é o arquivo XML de exemplo.The following is the example XML file.
<?xml version="1.0"?>
<root>
<subElement1>ABC</subElement1>
<subElement2>123</subElement2>
</root>
O código de exemplo a seguir instrui a XmlSchemaInference classe a inferir xs:string para elementos e atributos com conteúdo simples.The following example code instructs the XmlSchemaInference class to infer xs:string for elements and attributes with simple content.
XmlReader^ reader = XmlReader::Create("input.xml");
XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
XmlSchemaInference^ schema = gcnew XmlSchemaInference();
schema->TypeInference = XmlSchemaInference::InferenceOption::Relaxed;
schemaSet = schema->InferSchema(reader);
for each (XmlSchema^ s in schemaSet->Schemas())
{
s->Write(Console::Out);
}
XmlReader reader = XmlReader.Create("input.xml");
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchemaInference schema = new XmlSchemaInference();
schema.TypeInference = XmlSchemaInference.InferenceOption.Relaxed;
schemaSet = schema.InferSchema(reader);
foreach (XmlSchema s in schemaSet.Schemas())
{
s.Write(Console.Out);
}
Dim reader As XmlReader = XmlReader.Create("input.xml")
Dim schemaSet As XmlSchemaSet = New XmlSchemaSet()
Dim schema As XmlSchemaInference = New XmlSchemaInference()
schema.TypeInference = XmlSchemaInference.InferenceOption.Relaxed
schemaSet = schema.InferSchema(reader)
For Each s As XmlSchema In schemaSet.Schemas()
s.Write(Console.Out)
Next
Como a TypeInference propriedade foi definida como Relaxed , o esquema a seguir foi gerado.Because the TypeInference property was set to Relaxed, the following schema was generated.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="subElement1" type="xs:string" />
<xs:element name="subElement2" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
No código de exemplo acima, se a TypeInference propriedade não foi definida como Relaxed , a XmlSchemaInference classe teria padronizado Restricted e gerado o esquema a seguir.In the example code above, if the TypeInference property was not set to Relaxed, the XmlSchemaInference class would have defaulted to Restricted and generated the following schema.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="subElement1" type="xs:string" />
<xs:element name="subElement2" type="xs:unsignedByte" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Comentários
Se a TypeInference propriedade for definida como Relaxed , o tipo inferido de elementos e atributos no documento XML com conteúdo simples será sempre xs:string .If the TypeInference property is set to Relaxed, the inferred type of elements and attributes in the XML document with simple content is always xs:string. Se a TypeInference propriedade for definida como Restricted , tipos mais específicos serão inferidos, como xs:date , xs:decimal , xs:unsignedByte e assim por diante.If the TypeInference property is set to Restricted, more specific types are inferred, such as xs:date, xs:decimal, xs:unsignedByte, and so on.
O valor padrão da TypeInference propriedade é Restricted .The default value of the TypeInference property is Restricted.