C# XSD架构未按预期工作

C# XSD架构未按预期工作,c#,xml,xsd,C#,Xml,Xsd,我创建了这个xsd模式: <?xml version="1.0" encoding="ISO-8859-1" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:simpleType name="stringtype"> <xs:restriction base="xs:string"/> </xs:simpleType> <xs:simpleType

我创建了这个xsd模式:

 <?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="stringtype">
  <xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:simpleType name="inttype">
  <xs:restriction base="xs:positiveInteger"/>
</xs:simpleType>
<xs:simpleType name="dectype">
  <xs:restriction base="xs:decimal"/>
</xs:simpleType>
<xs:complexType name="RelativeText">
    <xs:attribute name="name" type="stringtype" use="required"/>
    <xs:attribute name="flow" type="stringtype" use="required"/>
    <xs:attribute name="amount" type="inttype"  use="required"/>
</xs:complexType>
<xs:complexType name="LineText">
    <xs:attribute name="name" type="stringtype" use="required"/>
</xs:complexType>
<xs:complexType name="BoxText">
    <xs:attribute name="width" type="dectype" use="required" />
    <xs:attribute name="height" type="dectype" use="required" />
    <xs:attribute name="x" type="dectype" use="required" />
    <xs:attribute name="y" type="dectype" use="required" />
</xs:complexType> 
<xs:complexType name="templatecontenttype">
  <xs:sequence>
    <xs:element name="line-text"        type="LineText" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="box-text"         type="BoxText"  minOccurs="0" maxOccurs="unbounded"/> 
    <xs:element name="relative-text"    type="RelativeText" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="output-directory" type="stringtype" use="required"/>
</xs:complexType>
<xs:element name="template-content" type="templatecontenttype"  />
</xs:schema>

我做错了什么???

元素的顺序是错误的。您已将顺序定义为
行文本
框文本
相对文本
,而不是示例中的
行文本
相对文本
框文本

因此,将模板xml更改为:

<?xml version='1.0'?>  
<template-content output-directory='D:\\output'>
    <line-text name='a' />
    <box-text name='c' x='1' y='2' width='2' height='2' />
    <relative-text name='b' flow='above' amount='1'/>
</template-content>

或者在模式中使用
而不是

<xs:all>
    <xs:element name="line-text" type="LineText" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="box-text" type="BoxText"  minOccurs="0" maxOccurs="unbounded"/> 
    <xs:element name="relative-text" type="RelativeText" minOccurs="0" maxOccurs="unbounded"/>
</xs:all>  

编辑
我想我误解了你的计划。使用
可以允许每个元素按任意顺序排列。但从您的模式来看,您似乎需要任意顺序的任意数量的元素。为此,您必须使用


我不想对它们进行排序,但如果我写xs:all,我会得到以下结果:未处理的异常:System.Xml.Schema.XmlSchemaException:all组的{particles}中所有粒子的{max occurs}必须为0或1。
<?xml version='1.0'?>  
<template-content output-directory='D:\\output'>
    <line-text name='a' />
    <box-text name='c' x='1' y='2' width='2' height='2' />
    <relative-text name='b' flow='above' amount='1'/>
</template-content>
<xs:all>
    <xs:element name="line-text" type="LineText" minOccurs="0" maxOccurs="unbounded"/>
    <xs:element name="box-text" type="BoxText"  minOccurs="0" maxOccurs="unbounded"/> 
    <xs:element name="relative-text" type="RelativeText" minOccurs="0" maxOccurs="unbounded"/>
</xs:all>  
<xs:choice maxOccurs="unbound">
    <xs:element name="line-text" type="LineText" />
    <xs:element name="box-text" type="BoxText" />
    <xs:element name="relative-text" type="RelativeText" />
</xs:choice>