我使用僅支持 XPath 1.0 的 xmllint --xpath。我知道 XPath 1.0 支持 concat() 之類的函式:https : //www.w3.org/TR/1999/REC-xpath-19991116/
但是,當我嘗試在 XPath 中使用它們以從 xml 檔案中提取內容時,出現如下錯誤:
xmllint --debug --xpath "//*[local-name()='artifactId' and contains(text(),'log4j')]/../concat(groupId/text(),' ',artifactId/text(),' ', version/text())" ~/aax1
XPath error : Invalid expression
//*[local-name()='artifactId' and contains(text(),'log4j')]/../concat(groupId/text(),' ',artifactId/text(),' ', version/text())
xmlXPathEval: evaluation failed
XPath evaluation failure
我正在閱讀 XPath 規范。尚不清楚如何在 XPath 運算式中使用這些函式(很清楚如何在 XSLT 中使用它們)。是否可以在謂詞之外的 XPath 1.0 中使用它們?
uj5u.com熱心網友回復:
XPath 1.0
如您所見,函式可能出現在謂詞中。
函式 my 也顯示為頂級運算式,在某些情況下可以提供幫助,例如,
concat(xp1, 'string', xp2)
其中xp1和xp2是全域指定的 XPath。
XPath 2.0
函式可能出現在 XPath 運算式的最后一步:
/e1/concat(e2, 'suffix')
也可以看看
- 如何使用 XPath 連接 XML 元素
- XPath concat() 不回傳多個專案
- XPath 中帶有字串的 Concat 函式
- XPath 如何處理 XML 名稱空間?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/379712.html
下一篇:在類建構式中向字串陣列添加新字串
