开发者

required element content

开发者 https://www.devze.com 2023-01-01 11:40 出处:网络
I\'m trying to create xsd for an element like this: <ElementType attr1=\"a\" attr2 =\"b\">mandatory_string</ElementType>

I'm trying to create xsd for an element like this:

<ElementType attr1="a" attr2 ="b">mandatory_string</ElementType>

and I want to make the mandatory_string required. What should I add to this xsd:

<xs:complexType name="ElementType">
开发者_运维知识库 <xs:simpleContent>
  <xs:extension base="xs:string">
   <xs:attribute name="attr1" type="StringLength1to2" use="required"/>
   <xs:attribute name="attr2" type="StringLength1to2" use="required"/>
  </xs:extension>
 </xs:simpleContent>
</xs:complexType>

Currently is optional. What's missing?


As mentioned in the comment the only way I know of is to use 'restriction's there is a restriction of 'pattern':

<xs:simpleType name="orderidtype">
    <xs:restriction base="xs:string">
        <xs:pattern value="[0-9]{6}"/>
    </xs:restriction>
</xs:simpleType>

I am not sure that is exactly what you are looking for though. Are you wondering if you can make the entire tag required, or just the string itself? If just the string you could just use a regex expression in the above example.

0

精彩评论

暂无评论...
验证码 换一张
取 消