這是我在 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/使用 Xerces-J 作為后端的在線 XSD 驗證服務,但它說:
[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頁面上它通過了驗證。怎么了?謝謝。
uj5u.com熱心網友回復:
請嘗試以下解決方案。
XSD 的正則運算式不同于一般的正則運算式。
冒號“:”和正斜杠“/”字符不需要轉義。
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>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/503687.html
下一篇:我應該如何正確驗證這一點?
