一个可以将两种给定的XSD数据类型连接为一种新的XSD数据类型吗? [英] Can one concatenate two given XSD data types into a new XSD data type?

查看:91
本文介绍了一个可以将两种给定的XSD数据类型连接为一种新的XSD数据类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出两种简单的数据类型,例如限制字符串type1type2,是否有可能定义type3来描述通过串联一个type1字符串和一个type2字符串形成的所有字符串?

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?

例如,考虑

<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>

然后我要定义type3这样

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

请注意,此示例仅用于说明,我知道如何组合正则表达式模式,但我的问题是如何通过XSD组合类型.

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.

推荐答案

XML Schema仅允许通过以下方式构造新的简单类型:

XML Schema only allows construction of new simple types by:

  • 限制(例如,type1可以限制为元音)
  • 列表(例如,type1的列表在其词法空间中具有A B D D E)
  • 联合(例如,上述类型的并集将是一个新的简单类型,其值空间包含A0C2等)
  • 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)

给出不可能"的答案总是有风险的,但是恐怕构建连接类型"的唯一方法就是通过使用连接的正则表达式限制xs:string来构造新的简单类型.

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.

我认为XML Schema不提供用于连接简单类型的通用机制的原因是,虽然在两个简单数据类型的词法空间上进行连接是有意义的,但对其值进行定义不一定是有意义的,也不是直截了当的空格,除了涉及字符串和模式构面的特定用例之外.

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.

这篇关于一个可以将两种给定的XSD数据类型连接为一种新的XSD数据类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆