繁体   English   中英

自定义类型的 XSD 1.0 验证失败

[英]XSD 1.0 validation fails for custom type

这是 XSD 文件中我的类型的定义(使用 xs:anyURI 不起作用):

  <xs:simpleType name="lastNavigType">
    <xs:restriction base="xs:string">
      <xs:pattern value="qrc\:\/help\/SBBL_[\d]+_[\w]+\.html"/>
    </xs:restriction>
  </xs:simpleType>

这是应该验证的属性:

<xs:attribute type="lastNavigType" name="last-navigated" use="required"/>

XML 文件有这个:

<helpviewer last-zoom="12" last-navigated="qrc:/help/SBBL_67_Graph_Terminology.html" bookmarks="" maximized="true">

我正在尝试在https://www.softwarebytes.org/xmlvalidation/使用在线 XSD 验证服务,它使用 Xerces-J 作为后端,但它说:

[Error] sbbl_app_settings.xml:20:118:cvc-pattern-valid: Value 'qrc:/help/SBBL_67_Graph_Terminology.html' is not facet-valid with respect to pattern 'qrc\:\/help\/SBBL_[\d]+_[\w]+\.html' for type 'lastNavigType'.
[Error] sbbl_app_settings.xml:20:118:cvc-attribute.3: The value 'qrc:/help/SBBL_67_Graph_Terminology.html' of attribute 'last-navigated' on element 'helpviewer' is not valid with respect to its type, 'lastNavigType'.

regex101.com页面上,它通过了验证。 怎么了? 谢谢。

请尝试以下解决方案。

XSD 的正则表达式不同于一般的正则表达式。

冒号“:”和正斜杠“/”字符不需要 escaping。

XML

<?xml version="1.0"?>
<helpviewer last-navigated="qrc:/help/SBBL_67_Graph_Terminology.html"/>

XSD

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="helpviewer">
        <xs:complexType>
            <xs:attribute name="last-navigated" use="required" type="lastNavigType"/>
        </xs:complexType>
    </xs:element>
    <xs:simpleType name="lastNavigType">
        <xs:restriction base="xs:string">
            <xs:pattern value="qrc:/help/SBBL_\d+_\w+_\w+\.html"/>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM