xsd:SimpleType:如何将属性限制为带有串联的特定值列表 [英] xsd:SimpleType: How to restrict attribute to list of specific values with concatenations
问题描述
我有 10 个带括号的"变量([EVENT]"、[PROTOCOL]"、[SESSION]"等...)我需要限制一个属性.有效情况是:
I have 10 "bracketed" variables ("[EVENT]", "[PROTOCOL]", "[SESSION]", etc...) I need to restrict an attribute. Valid cases are:
- 任何不带括号的字符串
- 提到了 10 个带括号的"变量
- 任何与常规字符串连接的括号变量,例如:我的[EVENT]对于[PROTOCOL]@google.com
- 空字符串
- Any string without brackets
- Mentioned 10 "bracketed" variables
- Any bracketed variable(s) concatenated with regular strings, for example: My[EVENT]for[PROTOCOL]@google.com
- Empty string
无效情况:
- 括号内的任何字符串,除了 10 个预定义的字符串
- 与串联相同
- 只有左括号或右括号的字符串
简而言之 - 括号内只允许预定义的变量,它们可以与任何字符串连接.
To be short - inside brackets only predefined variables are allowed and they can be concatenated with any string.
提前致谢
推荐答案
阅读正则表达式如下:一个或多个不包含括号的子字符串的连接,除了围绕 EVENT、PROTOCOL 或 SESSION 的那些. 这被简单地扩展到其他可接受的括号变量.
Read the regular expression as follows: The concatenation of one or more substrings containing no brackets except for those surrounding EVENT, PROTOCOL, or SESSION. This is trivially extended to additional acceptable bracketed variables.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:attribute name="attr">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[^\[\]]*"/>
<xs:pattern value="([^\[\]]*\[(EVENT|PROTOCOL|SESSION)\][^\[\]]*)+"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
这篇关于xsd:SimpleType:如何将属性限制为带有串联的特定值列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!