首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

xml有关问题

2012-04-07 
xml问题我想按照索引选择xml节点。例如int cnt5XmlNode node doc.SelectSingleNode(//book[cnt])//

xml问题
我想按照索引选择xml节点。
例如 
int cnt=5; 
XmlNode node = doc.SelectSingleNode("//book[cnt]");//这样不行 
XmlNode node = doc.SelectSingleNode("//book['" + cnt + "']");//这样也不行 
XmlNode node = doc.SelectSingleNode("//book[5]");//只有这样可行


该怎么做?

[解决办法]
XmlDocument.SelectSingleNode(string xpath);

参数传进去的是xpath格式.

C# code
int cnt=5;  XmlNode node = doc.SelectSingleNode(string.Contact( "//book[", cnt , "]"); 

热点排行