如何在C#中按以...开头的属性选择节点 [英] How to select nodes by attribute that starts with... in C#
本文介绍了如何在C#中按以...开头的属性选择节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个xml文档,我想按以'/employees/'开头的属性选择节点.
I have this xml document and I want to select nodes by attribute that starts with '/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#中,我会做这样的事情:
So in C#, I would do something like this:
parentNode.SelectNodes("//table/tr/th/a[@href='/employees/.....']")
使用C#可以吗?
谢谢!
推荐答案
简单的 starts-with
函数可以满足您的需求:
The simple starts-with
function does what you need:
parentNode.SelectNodes("//table/tr/td/a[starts-with(@href, '/employees/')]")
这篇关于如何在C#中按以...开头的属性选择节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文