Can one concatenate two given XSD data types into

2019-07-23 03:45发布

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条回答
Animai°情兽
2楼-- · 2019-07-23 04:07

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.

查看更多
登录 后发表回答