首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xml schema有关问题(关于无序和可选)

2012-03-15 
xmlschema问题(关于无序和可选)请问如何用XML Schema实现无序和可选的element和Attribute有这样的XML实例

xml schema问题(关于无序和可选)
请问如何用XML Schema实现无序和可选的element和Attribute

有这样的XML实例
<?xml version="1.0"?>
<root>
  <text att1="a" att2="b">
  <text att1="a" att2="b">
  <button att1="a" att2="b">
  <button att1="a" att2="b">
  <input att1="a" att2="b">
  <input att1="a" att2="b">
</root>

其中<text>,<button>,<input>可以有0个或多个,且无序,它们的属性无序且不必须有.
这样的限制该如何实现?

看了一下choice, all, sequence都不能满足,不知还有何方法?


[解决办法]
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2007 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:attributeGroup name="att">
<xs:attribute name="att1" type="xs:string" />
<xs:attribute name="att2" type="xs:string" />
</xs:attributeGroup>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="text" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="button" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="input" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="text">
<xs:complexType>
<xs:attributeGroup ref="att" />
</xs:complexType>
</xs:element>
<xs:element name="input">
<xs:complexType>
<xs:attributeGroup ref="att" />
</xs:complexType>
</xs:element>
<xs:element name="button">
<xs:complexType>
<xs:attributeGroup ref="att" />
</xs:complexType>
</xs:element>
</xs:schema>

热点排行