C# 我有这个xsd,我想做一个可选元素,这可能吗?
我有XSD:C# 我有这个xsd,我想做一个可选元素,这可能吗?,c#,xml,xsd,C#,Xml,Xsd,我有XSD: <?xml version="1.0" encoding="utf-8"?> <xs:schema id="UploadXSD" elementFormDefault="qualified" xmlns="http://tempuri.org/UploadXSD.xsd" xmlns:mstns="http://tempuri.org/UploadXSD.xsd" xmlns:xs="http://www.w3.org/2001/X
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
elementFormDefault="qualified"
xmlns="http://tempuri.org/UploadXSD.xsd"
xmlns:mstns="http://tempuri.org/UploadXSD.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="video">
<xs:complexType>
<xs:sequence>
<xs:element name="title" minOccurs="1" type="xs:string"></xs:element>
<xs:element name="description" type="xs:string"></xs:element>
<xs:element name="contributor" type="xs:string"></xs:element>
<xs:element name="cateogry" type="xs:string"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
最后一个元素可以是:
<category>
</category>
也可以是:
<subject>
</subject>
但是如何在XSD中将his表示为可选(类别|主题?您可以使用
xs:choice
元素来表示备选方案:
<xs:choice>
<xs:element name="category" type="xs:string"/>
<xs:element name="subject" type="xs:string"/>
</xs:choice>
您可以使用
xs:choice
元素来表示备选方案:
<xs:choice>
<xs:element name="category" type="xs:string"/>
<xs:element name="subject" type="xs:string"/>
</xs:choice>
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
elementFormDefault="qualified"
xmlns="http://tempuri.org/UploadXSD.xsd"
xmlns:mstns="http://tempuri.org/UploadXSD.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="video">
<xs:complexType>
<xs:sequence>
<xs:element name="title" minOccurs="1" type="xs:string"></xs:element>
<xs:element name="description" type="xs:string"></xs:element>
<xs:element name="contributor" type="xs:string"></xs:element>
<xs:choice>
<xs:element name="category" type="xs:string"/>
<xs:element name="subject" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
试试这个:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="UploadXSD"
elementFormDefault="qualified"
xmlns="http://tempuri.org/UploadXSD.xsd"
xmlns:mstns="http://tempuri.org/UploadXSD.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="video">
<xs:complexType>
<xs:sequence>
<xs:element name="title" minOccurs="1" type="xs:string"></xs:element>
<xs:element name="description" type="xs:string"></xs:element>
<xs:element name="contributor" type="xs:string"></xs:element>
<xs:choice>
<xs:element name="category" type="xs:string"/>
<xs:element name="subject" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>