XSD schema with choice

折月煮酒 提交于 2019-12-02 11:43:34

问题


I need to validate XML request data in below array:

<studyYear></studyYear>
<orgID></orgID>
<originID></originID>
<providerID></providerID>
<userOID></userOID>

Problem - I have to get either (orgID) or (userOID) or (originID and providerID) together. 'studyYear' will always be there. How I can realise it? If need more information just write. I referenced this link to use so as to try using xs:choice inside xs:all but could not get it working.


回答1:


This XSD,

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="r">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="studyYear" type="xs:string"/>
        <xs:choice>
          <xs:element name="orgID" type="xs:string"/>
          <xs:element name="userOID" type="xs:string"/>
          <xs:sequence>
            <xs:element name="orginID" type="xs:string"/>
            <xs:element name="providerId" type="xs:string"/>
          </xs:sequence>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

will require studyYear to be followed by one of the following cases,

  • orgID, or
  • userOID, or
  • both originID and providerID

as requested.



来源:https://stackoverflow.com/questions/40511238/xsd-schema-with-choice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!