开发者

Does XSD support validating the contents of an XML element?

I'm currently trying to create an XSD where I have a which can have only on of the following values:

<media_type>wmv</media-type>

or

<media_type>h264</media_type>

or

<media_type>mov</media_type>

I have found the <xs:choice/> element, but if I construct a complex type as such:

 <xs:element name="media_type" type="xs:string">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="h2开发者_Python百科64"/>
    <xs:element ref="wmv"/>
    <xs:element ref="flash"/>
   </xs:sequence>
   <xs:attribute name="media_id" use="required" type="xs:integer"/>
  </xs:complexType>
 </xs:element>

It will look for elements under <media_type/>. Is there a way to check the contents of an element in XSD?


Yep!

<xs:simpleType name="mediaType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="wmv"/>
    <xs:enumeration value="h264"/>
    <xs:enumeration value="mov"/>
  </xs:restriction>
</xs:simpleType>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜