您是采用代码优先方法还是契约优先方法(基于 WSDL+XSD 文件生成类)?
如果是后者,您可以使用定义所需正则表达式的 xsd:patterns 扩展相关的 XSD 类型。
例子:
<xsd:element name="elementName">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[^*+]"></xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
XMLBeans 应该为您生成必要的类、getter 和 setter。
但是,如果您直接通过 Java 代码创建 Web 服务,我假设您需要使用标准 Java 方法来处理正则表达式。我找到了 org.apache.xmlbeans.impl.regex.RegularExpression 的以下描述 - 也许它有帮助:
A.标准方式
RegularExpression re = new RegularExpression(regex);
if (re.matches(text)) { ... }
B.捕获组
RegularExpression re = new RegularExpression(regex);
Match match = new Match();
if (re.matches(text, match)) {
... // You can refer captured texts with methods of the Match class.
}
不区分大小写的匹配
RegularExpression re = new RegularExpression(regex, "i");
if (re.matches(text) >= 0) { ...}
选项
You can specify options to RegularExpression(regex, options) or setPattern(regex, options). This options parameter consists of the following characters.
"i"
This option indicates case-insensitive matching.
"m"
^ and $ consider the EOL characters within the text.
"s"
. matches any one character.
"u"
Redefines \d \D \w \W \s \S \b \B \< \> as becoming to Unicode.
"w"
By this option, \b \B \< \> are processed with the method of 'Unicode Regular Expression Guidelines' Revision 4. When "w" and "u" are specified at the same time, \b \B \< \> are processed for the "w" option.
","
The parser treats a comma in a character class as a range separator. [a,b] matches a or , or b without this option. [a,b] matches a or b with this option.
"X"
By this option, the engine confoms to XML Schema: Regular Expression. The match() method does not do subsring matching but entire string matching.
来源:http://www.docjar.com/docs/api/org/apache/xmlbeans/impl/regex/RegularExpression.html
在我看来,我建议采用契约/WSDL-first 方法。