XmlSchemaInference.Occurrence Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta il XmlSchemaInference.InferenceOption valore che influisce sulle dichiarazioni di occorrenza dello schema dedotte dal documento XML.
public:
property System::Xml::Schema::XmlSchemaInference::InferenceOption Occurrence { System::Xml::Schema::XmlSchemaInference::InferenceOption get(); void set(System::Xml::Schema::XmlSchemaInference::InferenceOption value); };
public System.Xml.Schema.XmlSchemaInference.InferenceOption Occurrence { get; set; }
member this.Occurrence : System.Xml.Schema.XmlSchemaInference.InferenceOption with get, set
Public Property Occurrence As XmlSchemaInference.InferenceOption
Valore della proprietà
Oggetto XmlSchemaInference.InferenceOption.
Esempio
In questo esempio viene illustrato il modo in cui l'occorrenza è interessata dalla Occurrence proprietà . Il codice di esempio deduce l'occorrenza da un file XML in due modi diversi: rilassato e limitato. Di seguito è riportato il file XML di esempio.
<?xml version="1.0"?>
<root>
<subElement1 attribute1="text">ABC</subElement1>
</root>
Il codice di esempio seguente indica alla XmlSchemaInference classe di dedurre l'occorrenza di elementi e attributi in modo rilassato.
XmlReader reader = XmlReader.Create("input.xml");
XmlSchemaSet schemaSet = new XmlSchemaSet();
XmlSchemaInference schema = new XmlSchemaInference();
schema.Occurrence = 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.Occurrence = XmlSchemaInference.InferenceOption.Relaxed
schemaSet = schema.InferSchema(reader)
For Each s As XmlSchema In schemaSet.Schemas()
s.Write(Console.Out)
Next
Poiché la Occurrence proprietà è stata impostata su Relaxed, è stato generato lo schema seguente.
<?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 minOccurs="0" name="subElement1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="attribute1" type="xs:string" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Nel codice di esempio precedente, se la Occurrence proprietà non è stata impostata su Relaxed, la XmlSchemaInference classe avrebbe impostato come predefinito Restricted e generato lo schema seguente.
<?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">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="attribute1" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Commenti
Se la Occurrence proprietà è impostata su Restricted, la prima volta che vengono rilevati elementi nel documento XML, la dichiarazione dello schema viene dedotta come minOccurs="1". Quando vengono rilevati attributi, la dichiarazione dello schema viene dedotta come use="required".
Se la Occurrence proprietà è impostata su Relaxed, le dichiarazioni dello schema degli elementi vengono dedotte come minOccurs="0"e le dichiarazioni dello schema degli attributi vengono dedotti come use="optional".
Il valore predefinito della Occurrence proprietà è Restricted.