Schema里会限制元素的出现顺序的.如下: a,b,c的出现个数可以是0到无限,但是b后面不能够出现a,c后面不能够出现a或者b,
而a的前面则不能光出现b或者c.推荐xmlspy,像我这样不懂的人都可以轻松写schema文件.<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="roote">
<xs:annotation>
<xs:documentation>Comment describing your root element</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="a" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="b" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="c" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

解决方案 »

  1.   

    不好意思,上面没有写好就贴出来了,再改了下:<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="roote">
    <xs:annotation>
    <xs:documentation>Comment describing your root element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
    <xs:sequence>
    <xs:element name="root" minOccurs="0" maxOccurs="unbounded">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="a" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="b" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="c" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>
    sample xml:-------------------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <!--Sample XML file generated by XMLSPY v2004 rel. 4 U (http://www.xmlspy.com)-->
    <roote xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="E:\jb\Untitled1.xsd">
    <root>
    <a>Text</a>
    <a>Text</a>
    <b>Text</b>
    <c>Text</c>
    <c>Text</c>
    </root>
    <root>
    <a>Text</a>
    <a>Text</a>
    <b>Text</b>
    <b>Text</b>
    <c>Text</c>
    <c>Text</c>
    </root>
    <root>
    <b>Text</b>
    <b>Text</b>
    <c>Text</c>
    </root>
    </roote>
      

  2.   

    有一种可以打乱顺序的方法:使用all而不是 sequence
    但是XML Schema规定,使用all后 元素不能重复了。这样也不合楼主的要求。
    相比之下,还是用sequence吧。
    因为你可以生成xml的地方可以用代码控制顺序后再输出
      

  3.   

    谢谢各回贴,pigo的很接近了,差一点点,只要是多加了不需要的顺序限定,哎,难啊
      

  4.   

    找到了
    choice min=0 max=unbound