Can one concatenate two given XSD data types into a new XSD data type?

跟風遠走 提交于 2019-12-24 09:35:56

问题


Given two simple data types, say, restricted strings type1, type2, is there a possibility to define type3 describing all strings formed by concatenating one type1 string plus one type2 string?

For example, consider

<xsd:simpleType name="type1">
 <xsd:restriction base="xsd:string">
  <xsd:pattern value="[A-Z]"></xsd:pattern>
 </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="type2">
 <xsd:restriction base="xsd:string">
  <xsd:pattern value="[0-9]"></xsd:pattern>
 </xsd:restriction>
</xsd:simpleType>

Then I would like to define type3 such that

A0 -> valid
B1 -> valid
AA -> invalid
etc...

Note that this example is just for illustration, I know how to combine the regex patterns, but my question is how to combine the types via XSD.


回答1:


XML Schema only allows construction of new simple types by:

  • restriction (e.g., type1 could be restricted to vowels)
  • list (e.g., a list of type1 would have A B D D E in its lexical space)
  • union (e.g., the union of the above types would be a new simple type with a value space containing A, 0, C, 2, etc)

It is always risky to give the answer "not possible", but I am afraid that the only way to build a "concatenated type" is thus to construct a new simple type by restricting xs:string with the concatenated regular expressions.

I think that the reason why XML Schema does not provide a general mechanism for concatenating simple types is that, while concatenation makes sense on the lexical space of two simple data types, it is not necessarily meaningful nor straightforward to define on their value spaces, besides the specific use case at hand involving strings and the pattern facet.



来源:https://stackoverflow.com/questions/44020639/can-one-concatenate-two-given-xsd-data-types-into-a-new-xsd-data-type

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