我有这样的 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