我有这个 xml 文档,我想通过以“/employees/”开头的属性来选择节点。
<table>
<tr>
<td>
<a href="/employees/1.html" title="Employee 1">Employee 1</a>
</td>
<td>Robert</td>
</tr>
<tr>
<td>
<a href="/employees/2.html" title="Employee 2">Employee 2</a>
</td>
<td>Jennifer</td>
</tr>
</table>
所以在 C# 中,我会做这样的事情:
parentNode.SelectNodes("//table/tr/th/a[@href='/employees/.....']")
这可以用 C# 实现吗?
谢谢!
最佳答案
简单的 starts-with
函数可以满足您的需求:
parentNode.SelectNodes("//table/tr/td/a[starts-with(@href, '/employees/')]")
关于c# - 如何在 C# 中按以...开头的属性选择节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10801399/