【发布时间】:2013-08-30 12:35:49
【问题描述】:
我有一个奇怪的问题,我的 Castor-Maven-Plugin 生成的 java 类将无法解组 XML 字符串的内容。
我要验证的 XML 如下所示:
...
<mediaType>audio/media</mediaType>
...
我正在根据以下模式对其进行验证:
(audio|video|document|application|example|image|message|model|multipart|text)/.+
Castor 从中生成类的 XSD 的相关部分:
...
<xs:simpleType name="mediaType">
<xs:annotation>
<xs:documentation>
The internet media type of the paired file. For example, a MP3 file would be audio/mpeg.
</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:pattern value="(audio|video|document|application|example|image|message|model|multipart|text)/.+"/>
</xs:restriction>
</xs:simpleType>
...
当我尝试解组 XML 字符串时抛出以下异常:
org.exolab.castor.xml.MarshalException: The following exception occured while validating field: _mediaType of class: my.domain.GeneratedClass: audio/mpegdoes not match the required regular expression: "(audio|video|document|application|example|image|message|model|multipart|text)/.+"{File: [not available]; line: 23; column: 12}...
现在,根据 IntelliJ 的 XML 验证和我尝试过的所有其他正则表达式工具,这应该不是问题。为什么 Castor 似乎这么认为?
【问题讨论】:
-
各个地方的旧帖子表明 Castor 上的旧版本存在错误。我猜您运行的是较新版本,但您使用的是什么版本?
-
我使用的是 1.3.0.1,虽然我刚刚更新到 1.3.1。我和一个同事刚刚解决了这个问题。见下文。
标签: java xml regex maven castor