我正在使用提供的 XSD 驗證 XML,其中一個元素說姓氏,需要允許撇號或單引號字符 ('),但是當我使用以下代碼運行驗證時,它不會驗證為 XSD模式具有 (') 的轉義 ' 格式。是否有一個選項允許使用模式中的 ' 值進行驗證以匹配 '。
XmlSchemaSet schema = new XmlSchemaSet();
schema.Add(namespaceXsd, schemaPath);
string validationMessage = string.Empty;
docTOValidate.Validate(schema, (s, e) =>
{
validationMessage = e.Message;
});
下面是在 XSD 中應用于姓氏元素的模式,正則運算式具有轉義的 '. 所以這是我將 Last' 作為值傳遞,但驗證失敗。
<xsd:element name="lastName">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[A-Z]{1}[A-Z\p{Zs};'\-]{1,29}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
編輯下面是示例 xml 和錯誤訊息,無法復制所有檔案名,但下面顯示了有例外的檔案
<Root>
<Key>
<ID>
<S>000</S>
<UD>111<UD>
</ID>
...
...
...
<Key>
<Data>
<firstIn>N</firstIn>
<lastName>NAME'</lastName>
...
...
...
...
</Data>
</Root>
下面是例外
The 'http://www.ui-icon.org/ns/xxxx:lastName' element is invalid - The value 'NAME`' is invalid according to its datatype 'String' - The Pattern constraint failed.
即使我使用轉義值傳遞名稱,我仍然會收到驗證錯誤,盡管正則運算式可以很好地驗證 O'NAME
The 'http://www.ui-icon.org/ns/namespace:lastName' element is invalid - The value 'O'NAME' is invalid according to its datatype 'String' - The Pattern constraint failed.
uj5u.com熱心網友回復:
您撰寫的模式由 XML 決議器提供給 XSD 模式處理器
[A-Z]{1}[A-Z\p{Zs};'\-]{1,29}
你也可以直接這樣寫,因為在這種情況下轉義撇號是不必要的。
'無論您的問題是什么,它都與and之間的區別無關,'模式處理器甚至從未見過。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/512777.html
