我有一个XML模式(XSD),它将元素定义为必需元素(称之为父元素);让我们说,这个父级有五个子元素,它们都可以是可选的,但必须至少有一个子元素.
我怎样才能在xsd中指定它?
澄清:孩子是不同的元素和可选的.
例如.
<Parent> <Child1>contents are different to other siblings and arbitrary</Child1> <Child2>can be text,a simple element,or another complex element</Child2> <Child3>etc.. etc</Child3> </Parent> <xs:complexType name="Parent"> <xs:sequence> <xs:element minOccurs="0" name="Child1" type="xs:string"/> <xs:element minOccurs="0" name="Child2" /> <xs:element minOccurs="0" name="Child3" /> </xs:sequence> </xs:complexType>
即使每个孩子都是可选的,父母也需要至少有一个孩子.
始终有直接的方法:
<xs:complexType name="Parent"> <xs:choice> <xs:sequence> <xs:element name="Child1"/> <xs:element name="Child2" minOccurs="0"/> <xs:element name="Child3" minOccurs="0"/> </xs:sequence> <xs:sequence> <xs:element name="Child2"/> <xs:element name="Child3" minOccurs="0"/> </xs:sequence> <xs:sequence> <xs:element name="Child3"/> </xs:sequence> </xs:choice> </xs:complexType>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。