Prevent Empty Elements in XML via XSD

后端 未结 2 1299
余生分开走
余生分开走 2021-01-25 09:11

I\'m working on an XSD file and when validating an XML file with it I want to restrict empty elements. Eg.,

this is not empty

相关标签:
2条回答
  • 2021-01-25 09:44

    You can have minOccurs="0" to require the tag, then have a validation regex that checks for one or more characters.

    0 讨论(0)
  • 2021-01-25 09:47

    You can do something like

    <xs:simpleType name="myString">
      <xs:restriction base="xs:string">
         <xs:minLength value="1"/>
      </xs:restriction>
    </xs:simpleType>
    
    <xs:element name="root" type="myString"></xs:element>
    

    However that will still match on <root> </root> but you could use a regex restriction to change that if it is an issue.

    0 讨论(0)
提交回复
热议问题