[英]line breaks and spaces in XML Schematron
我有個問題。 我在XML中有換行符,空格和制表符。 像這樣:
<value xs:type="DV_TEXT"><value>1111\this is what it is used for, this could be a
really long line or even
multiple lines, just like
what you are reading now
</value></value>
org.w3c.dom中的Java中的setTextContent和getTextContent處理得很好。 沒問題。
但是現在,我正在生成Schematron以進行驗證,以檢查此字符串是否確實出現在值中。 Schematron是從定義測試字符串的定義文件中生成的
生成的Schematron,斷言測試如下所示:
test="(matches(.,'1111\this is what it is used for, this could be a really long line or even
multiple lines, just like
what you are reading now'))"
然后,當我驗證時,還會出現更多問題。 首先換行。 似乎在生成Schematron的定義文件中有\\r\\n
而不是\\n
。 但是,我必須指望這一點。 如果我替換所有

僅

一些錯誤消失了。 以及如何確定XML文件也只有

作為換行符?
我想我需要更改測試斷言中附帶的字符串,例如,僅用\\n
替換所有\\r\\n
\\n
。
我已經做到了,並且部分解決了我的問題。 我還要考慮什么?
歡迎所有提示。
如果您希望節點文本不管其空格如何都有效,請使用normalize-space函數功能:
normalize-space函數返回帶空格的參數字符串,該字符串通過去除前導和尾隨空格並將空格字符序列替換為單個空格來規范化。 [...]
因此,這應該工作:
test="(matches(normalize-space(.),'1111\this is what it is used for, this could be a really long line or even multiple lines, just like what you are reading now'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.