开发者

Restricting XML attribute content via XSD

开发者 https://www.devze.com 2023-02-19 20:45 出处:网络
I\'ve got some XML like that: <sometag datatype=\"xs:string\" .../> <sometag datatype=\"xs:int\" .../>

I've got some XML like that:

<sometag datatype="xs:string" .../>
<sometag datatype="xs:int" .../>

As one can see, the content of the attribute "datatype" should refer to the basic XML datatypes. Currently I'm using the some self-defined simpleType like the following:

<xs:simpleType name="contentDataType">
  <xs:restriction base="xs:string">
    <xs:enumeration value="string"/>
    <xs:enumeration value="int"/>
    <xs:e开发者_如何学编程numeration value="boolean"/>
    <xs:enumeration value="float"/>
  </xs:restriction>
</xs:simpleType>

Is there a way of restricting the content to the names of the XML basic types via an XSD?


The names of the XML datatypes aren't datatypes in themselves, so your enumeration is pretty much the only way to do this - that or a regular expression. Either way you need to provide a string based restriction that allows only a list of values or a filter that only allows those values through. I'd choose the enumeration purely for clarities sake.

0

精彩评论

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