Sdílet prostřednictvím


XmlSchemaInference.Occurrence Vlastnost

Definice

Získá nebo nastaví XmlSchemaInference.InferenceOption hodnotu, která ovlivňuje deklarace výskytu schématu odvozené z dokumentu 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

Hodnota vlastnosti

XmlSchemaInference.InferenceOption

Objekt XmlSchemaInference.InferenceOption.

Příklady

Tento příklad ukazuje, jak je výskyt ovlivněn Occurrence vlastností. Příklad kódu odvozuje výskyt ze souboru XML dvěma různými způsoby: uvolněný a omezený. Následuje příklad souboru XML.

<?xml version="1.0"?>
<root>
    <subElement1 attribute1="text">ABC</subElement1>
</root>

Následující ukázkový kód dává třídě pokyn XmlSchemaInference , aby odvozoval výskyt prvků a atributů uvolněným způsobem.

XmlReader^ reader = XmlReader::Create("input.xml");
XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
XmlSchemaInference^ schema = gcnew XmlSchemaInference();

schema->Occurrence = 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.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

Vzhledem k tomu, že Occurrence vlastnost byla nastavena na Relaxed, bylo generováno následující schéma.

<?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>

V příkladu výše uvedený kód, pokud Occurrence vlastnost nebyla nastavena na Relaxed, XmlSchemaInference třída by měla výchozí hodnotu Restricted a vygenerovala následující schéma.

<?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>

Poznámky

Occurrence Pokud je vlastnost nastavena na Restricted, při prvním zobrazení elementů v dokumentu XML se deklarace schématu odvozuje jako minOccurs="1". Pokud jsou zjištěny atributy, deklarace schématu je odvozena jako use="required".

Occurrence Pokud je vlastnost nastavena na Relaxed, deklarace schématu elementu jsou odvozeny jako minOccurs="0"a deklarace schématu atributu jsou odvozeny jako use="optional".

Výchozí hodnota Occurrence vlastnosti je Restricted.

Platí pro