如何使 XML 模式中的元素可选? [英] How to make an element in XML schema optional?
本文介绍了如何使 XML 模式中的元素可选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我得到了这个 XML 模式:
So I got this XML schema:
<?xml version="1.0"?> <xs:schema version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="request">
<xs:complexType>
<xs:sequence>
<xs:element name="amenity">
<xs:complexType>
<xs:sequence>
<xs:element name="description" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element> </xs:schema>
如何使 description 元素成为可选元素?因此,带有 description 元素和不带 description 元素的 XML 都将根据 XSD 进行验证.
How do I make the description element optional? So both XML with the description element and without will validate against the XSD.
推荐答案
试试这个
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="1" />
如果你想要 0 或 1 个描述"元素,或者
if you want 0 or 1 "description" elements, Or
<xs:element name="description" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
如果你想要 0 到无穷多个描述"元素.
if you want 0 to infinity number of "description" elements.
这篇关于如何使 XML 模式中的元素可选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文