未排序且仅一个未绑定项的XSD验证

未排序且仅一个未绑定项的XSD验证,xsd,Xsd,我有这样一个xml文件: <customer> <field1 /> <field2 /> <field3> <item1 /> </field3> <field3> <item1 /> </field3> </customer> 字段*可以以任何顺序出现,只有字段3可以出现多次 如何创建XSD文件来验证这一点 谢谢大家! 试试这个

我有这样一个xml文件:

<customer>
  <field1 />
  <field2 />
  <field3>
    <item1 />
  </field3>
  <field3>
    <item1 />
  </field3>
</customer>

字段*可以以任何顺序出现,只有字段3可以出现多次

如何创建XSD文件来验证这一点

谢谢大家!

试试这个 我不是大师,但这似乎有效

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="customer" type="customerType"/>
  <xs:complexType name="customerType">
    <xs:sequence>
      <xs:element name="field1" minOccurs="1" maxOccurs="1">
      </xs:element>
      <xs:element name="field2" minOccurs="1" maxOccurs="1">
      </xs:element>
      <xs:element name="field3" type="field3Type"
                  minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="field3Type">
    <xs:sequence>
      <xs:element name="item1">
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

工具 我使用了,但是有很多编辑器可以验证XML

链接 您可能还对从XML文件生成XSD感兴趣

试试这个 我不是大师,但这似乎有效

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="customer" type="customerType"/>
  <xs:complexType name="customerType">
    <xs:sequence>
      <xs:element name="field1" minOccurs="1" maxOccurs="1">
      </xs:element>
      <xs:element name="field2" minOccurs="1" maxOccurs="1">
      </xs:element>
      <xs:element name="field3" type="field3Type"
                  minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="field3Type">
    <xs:sequence>
      <xs:element name="item1">
      </xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

工具 我使用了,但是有很多编辑器可以验证XML

链接
您可能还对从XML文件生成XSD感兴趣

哼,xsd真的不适合做这种工作。无论如何,如果我没有犯错误,这应该会起作用:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/NewXMLSchema"
xmlns:tns="http://www.example.org/NewXMLSchema" elementFormDefault="qualified">

  <element name="customer" type="tns:customerType"/>
  <complexType name="customerType">
    <sequence>
      <element>
        <complexType>
          <all>
            <element>
              <complexType>
                <sequence>
                  <element ref="tns:field3" maxOccurs="unbounded"/>
                  <element ref="tns:field1" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
            <element>
              <complexType>
                <sequence>
                  <element ref="tns:field3" maxOccurs="unbounded"/>
                  <element ref="tns:field2" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
            <element>
              <complexType>
                <sequence>
                  <element ref="tns:field3" maxOccurs="unbounded"/>
                  <element ref="tns:field4" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
          </all>
        </complexType>
      </element>
      <element ref="tns:field3" maxOccurs="unbounded" />
    </sequence>
  </complexType>
  <complexType name="field1Container"/>
  <complexType name="field2Container"/>
  <complexType name="field3Type">
    <sequence>
      <element name="item1"/>
    </sequence>
  </complexType>
  <complexType name="field4Container"/>
  <element name="field3" type="tns:field3Type"/>
  <element name="field1"/>
  <element name="field2"/>
  <element name="field4"/>
</schema>

哼,xsd真的不适合做这种工作。无论如何,如果我没有犯错误,这应该会起作用:

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/NewXMLSchema"
xmlns:tns="http://www.example.org/NewXMLSchema" elementFormDefault="qualified">

  <element name="customer" type="tns:customerType"/>
  <complexType name="customerType">
    <sequence>
      <element>
        <complexType>
          <all>
            <element>
              <complexType>
                <sequence>
                  <element ref="tns:field3" maxOccurs="unbounded"/>
                  <element ref="tns:field1" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
            <element>
              <complexType>
                <sequence>
                  <element ref="tns:field3" maxOccurs="unbounded"/>
                  <element ref="tns:field2" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
            <element>
              <complexType>
                <sequence>
                  <element ref="tns:field3" maxOccurs="unbounded"/>
                  <element ref="tns:field4" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
          </all>
        </complexType>
      </element>
      <element ref="tns:field3" maxOccurs="unbounded" />
    </sequence>
  </complexType>
  <complexType name="field1Container"/>
  <complexType name="field2Container"/>
  <complexType name="field3Type">
    <sequence>
      <element name="item1"/>
    </sequence>
  </complexType>
  <complexType name="field4Container"/>
  <element name="field3" type="tns:field3Type"/>
  <element name="field1"/>
  <element name="field2"/>
  <element name="field4"/>
</schema>


当然有问题。我发表评论时没有问题。当然有问题。我发表评论时没有问题。AJ,谢谢你的回答。但问题是字段*可能以任何顺序出现-xs:all如果我可以使用maxOccurs=“unbounded”。AJ,谢谢你的回答。但问题是,字段*可能以任何顺序出现-xs:all如果可以使用maxOccurs=“unbounded”就完美了。