我剛剛設計了一個XPath表達式來查找所有空元素並在結束後直接返回文本。XPath normalize-space()不能用作step函數嗎?
我已經在OXYGEN中測試了這個XPath,並返回了我正在尋找的內容。由於我還不知道的原因,我無法在Visual Studio(C#)中這樣做。
XPath表達式:
//xref[not(@href)]/normalize-space(substring(following-sibling::text()[1], 1, 20))
這裏是DITA(XML)文件,該文件中的XPath的搜索的一個示例:
<?xml version="1.0" encoding="UTF-8"?>
<topic id="topic_50038EEEBC214A0EBF0660DCFFCF69C6">
<title> Postulated Piping Failures in Fluid Systems Outside of
Containment</title>
<prolog>
<author/>
</prolog>
<body>
<p>
<b>Definitions</b>
</p>
<p>
<u>Leakage</u>
</p>
<p>
<xref
href="t1.3.2.2_System Quality Group Classifications.dita#topic_AE87340A0F424D07B0E301E243CCB7B2"
format="dita" scope="local"><?xm-replace_text System Quality Group Classifications?></xref>
TEXT
</p>
<p>
<u>
</u>TEXT
<xref></xref>5.2
</p>
</body>
</topic>
在氧氣,使用XPath棒,結果是「5.2」,這正是我想要檢索的。
這裏是C#來檢索節點:
String xPathFindXREF = "//xref[not(@href)]/normalize-space(substring(following-sibling::text()[1], 1, 20))";
XmlNodeList xmlNodeList = currFile.SelectNodes(xPathFindXREF);
是否有可能使用XPath功能,如在C#normalize-space()
?
可能重複[如何獲得normalize-space()xpath函數的工作?](https://stackoverflow.com/questions/1829176/how-to-get-the-normalize-space-xpath-function對工作) –