asp.net + xml
一个xml文件绑定在数据控件里面.
<?xml version= "1.0 " encoding= "UTF-8 " standalone= "yes "?>
<?xml-stylesheet type= "text/xsl " href= "/listskin/skin/listskin19.xsl "?>
<root>
<list id= "2007053000019480 " title= "斯柯达明锐6月6日上市 价格将同步正式宣布 " url= "/NewsHtml/2007/05/30/20070530000194801.htm " />
<list id= "2007060801141390 " title= "新宝马3系敞篷和双门轿跑上市 "url= "/NewsHtml/2007/06/08/20070608011413901.htm " >
<list id= "2007060801130570 " title= "2007北美新车质量报告 福特获得最多荣誉 " url= "/NewsHtml/2007/06/08/20070608011305701.htm "/>
<list id= "2007060801156310 " title= "未来十大焦点汽车安全技术 " url= "/NewsHtml/2007/06/08/20070608011563101.htm "/>
</root>
怎么样来动态判断我选择的是第几条呢.比如说我选择了 "新宝马3系敞篷和双门轿跑上市 "我要怎么样知道它就是xml文件当中的第三条呢?
------解决方案--------------------试试:
using System.Xml;
XmlDocument doc = new XmlDocument();
doc.Load( "yourXml.xml ");
XmlNode ;
XmlNode root = doc.DocumentElement;
returnNode=root.SelectSingleNode( "list[@title= '新宝马3系敞篷和双门轿跑上市场 '] ");
//returnNode就是你的节点了
------解决方案--------------------使用xpath中的position()函数
举例:root.selectSingleNode( "/list[position()=2] ");