xml文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!-- 链接串,也可以不使用此串 -->
<add key="ConnectionString" value="server=chang;User ID=Power_User;Password=password;database=PowerFromYL;Connection Reset=FALSE;Connect Timeout=30" />
<add key="test" value="Edit it">
</add>
</appSettings>
</configuration>doc.Load(cfgFile);
XmlNode aNode;
aNode = doc.SelectSingleNode("configuration/appSettings/add"); //可以选中第一个节点
...
//下面这样就不能选中第一个节点
aNode = doc.SelectSingleNode("configuration/appSettings/add[key='test']");
...
这是为什么啊,如何才能让第二条语句选中我想要的节点??
请指点迷津啊
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!-- 链接串,也可以不使用此串 -->
<add key="ConnectionString" value="server=chang;User ID=Power_User;Password=password;database=PowerFromYL;Connection Reset=FALSE;Connect Timeout=30" />
<add key="test" value="Edit it">
</add>
</appSettings>
</configuration>doc.Load(cfgFile);
XmlNode aNode;
aNode = doc.SelectSingleNode("configuration/appSettings/add"); //可以选中第一个节点
...
//下面这样就不能选中第一个节点
aNode = doc.SelectSingleNode("configuration/appSettings/add[key='test']");
...
这是为什么啊,如何才能让第二条语句选中我想要的节点??
请指点迷津啊
{
XmlNode xmlDocNode = null;
XmlDocument doc =new XmlDocument();
string strXmlPath =Server.MapPath("XMLFile1.xml");
doc.Load(strXmlPath);
xmlDocNode =doc.SelectSingleNode("configuration/appSettings/add[@key='test']");
//下面的取出的值 Edit it
//xmlDocNode.Attributes.Item(1).InnerText;
}你拉下了转义字符,上面给出你取值方法了。
快速监视 是个不错的东西。