0

我有这样的 XML 片段。我需要进行 XSD 验证,例如:如果字段属性“名称”是端口,那么它必须匹配正则表达式以确定它是否是数字(如“\p{Nd}+”)

<Data>
    <Attributes>
        <Field name="nodeType">abcd</Field>
        <Field name="port">5462</Field>
    </Attributes>
</Data>

在我的 XSD 中,我使用了如下所示的断言

<xs:element name="Field" maxOccurs="unbounded" minOccurs="0">
                                <xs:complexType>
                                  <xs:simpleContent>
                                    <xs:extension base="xs:string">
                                      <xs:attribute type="xs:string" name="name" use="optional"/>
                                      <xs:assert test="if(@name='port') then matches($value,'\p{Nd}+') else false())"/>
                                    </xs:extension>
                                  </xs:simpleContent>
                                </xs:complexType>
                              </xs:element>

但是,当我运行时,我得到以下异常抛出

xml is NOT valid reason:org.xml.sax.SAXParseException;cvc-xpath.3.13.4.2a: XPST0003 - Assertion XPath expression ('if(@name='port') then matches($value,'\p{Nd}+') else false())') on the schema type '#AnonType_FieldAttributesDataContainerRtms' couldn't compile successfully
4

1 回答 1

0

你有一个杂散的右括号:

false())
       ^

用于比较的撒克逊错误消息:

Error at xs:assert on line 7 column 102 of test.xsd:
  Unexpected token ")" beyond end of expression
于 2017-08-28T12:16:25.113 回答