已經嘗試過//*[ends-with(text()='updated the meeting')],//*[ends-with(text(),'updated the meeting')]但沒有奏效。

uj5u.com熱心網友回復:
您可以normalize-space() 在此處使用一種方法:
//*[normalize-space() = 'updated the meeting']
要么
//span[normalize-space() = 'updated the meeting']
上面的解決方案在這里可以作業,但如果之前有一些文本,updated the meeting你more text presenting, updated the meeting可以使用它:
//*[ends-with(normalize-space(text()), 'updated the meeting']
或這個
//span[ends-with(normalize-space(text()), 'updated the meeting']
uj5u.com熱心網友回復:
是的,ends-with()并且text()可以在 XPath 中一起使用,但是...
不,它不會按照您嘗試的方式作業。
不,使用
normalize-space()(正如其他回答者提供的那樣)不是解決問題的方法;這樣的“解決方案”不會測驗另一個字串末尾是否存在子字串。
第一個問題: ends-with()需要 XPath 2.0。如果您堅持使用 XPath 1.0,這里是(詳細的)解決方法。
第二個問題:即使你的處理器支持 XPath 2.0,text()作為它的第一個引數傳遞也是一個錯誤,因為ends-with()它期望一個字串作為它的第一個引數,而不是一個文本節點序列。 這種常見的混淆也出現在 XPath 與contains()函式中。
因此,要選擇最后一個文本節點子節點以 結尾的所有元素'updated the meeting',請使用以下 XPath 2.0 運算式:
//*[text()[last()][ends-with(.,'updated the meeting')]]
要忽略任何可能的尾隨空格:
//*[text()[last()][ends-with(normalize-space(),'updated the meeting')]]
使用此技術將上述 XPath 2.0 運算式轉換為 XPath 1.0 留作練習。
uj5u.com熱心網友回復:
如圖所示,ends-with 不起作用。這是text()包括新行和引號的值
xmllint --shell test.html
/ > cat //div/span/text()
-------
" updated the meeting"
添加normalize-space()
xmllint --xpath 'normalize-space(//div/span/text())' test.html ; echo
" updated the meeting"
使用contains()
xmllint --xpath '//*[contains(normalize-space(text()), "updated the meeting")]' test.html ; echo
<span>
" updated the meeting"
</span>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/444238.html
