<?xml version="1.0" encoding="utf-8"?>
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <properties url="F:\Crm\Crm\bin\database.config"/>
<settings>
<setting useStatementNamespaces="${useStatementNamespaces}"/>
<setting cacheModelsEnabled="true"/>
<setting validateSqlMap="false"/>
</settings>
<providers embedded="providers.config,Crm"/>
<database>
<provider name="sqlServer2.0"/>
<dataSource name="iBatisNet" connectionString="data source=${datasource};database=${database};user id=${userid};password=${password};connection reset=false;connection lifetime=5; min pool size=1; max pool size=50"/>
</database>
<sqlMaps>
<sqlMap embedded="Map.SqlClient.BUAction.xml,Crm"/>
<sqlMap embedded="Map.SqlClient.BUActionSub.xml,Crm"/> </sqlMaps>
</sqlMapConfig>要求找到 properties 节点.并把url的值改成"E:\CRM"
<sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <properties url="F:\Crm\Crm\bin\database.config"/>
<settings>
<setting useStatementNamespaces="${useStatementNamespaces}"/>
<setting cacheModelsEnabled="true"/>
<setting validateSqlMap="false"/>
</settings>
<providers embedded="providers.config,Crm"/>
<database>
<provider name="sqlServer2.0"/>
<dataSource name="iBatisNet" connectionString="data source=${datasource};database=${database};user id=${userid};password=${password};connection reset=false;connection lifetime=5; min pool size=1; max pool size=50"/>
</database>
<sqlMaps>
<sqlMap embedded="Map.SqlClient.BUAction.xml,Crm"/>
<sqlMap embedded="Map.SqlClient.BUActionSub.xml,Crm"/> </sqlMaps>
</sqlMapConfig>要求找到 properties 节点.并把url的值改成"E:\CRM"
doc.Load(@"e:\1.xml");XmlElement node = (XmlElement)doc.SelectSingleNode("//properties");
node.SetAttribute("url", @"E:\CRM");doc.Save(@"e:\1.xml");
http://dotnet.aspx.cc/article/7b4c7a42-4cdf-40d1-b293-e86da109a34c/read.aspx找到属性节点都设置即可XmlNode xx = doc.SelectSingleNode("//xxx名称空间:properties/@url",nsmanager)
xx.value="E:\\CRM"
node.SetAttribute("url", FilePath);
我调试时node =null
--->
你得象孟子说的那样带着命名空间~~~~
string FilePath = Model.BaseLogin.AppBllFilePath+ @"\sqlmap.config";
doc.Load(FilePath);//doc加载没错
XmlElement node = (XmlElement)doc.SelectSingleNode("//properties");//node 节点为空
node.SetAttribute("url", FilePath);
doc.Save(FilePath);
哪位大哥指点,这代码哪里有问题
doc.Load(@"e:\1.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("xx", "http://ibatis.apache.org/dataMapper");
XmlElement node = (XmlElement)doc.SelectSingleNode("/xx:sqlMapConfig/xx:properties", nsmgr);
node.SetAttribute("url", @"E:\CRM"); doc.Save(@"e:\1.xml");
XmlDocument doc = new XmlDocument();
string FilePath = Model.BaseLogin.AppBllFilePath+ @"\sqlmap.config";
doc.Load(FilePath);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("map", "http://ibatis.apache.org/dataMapper");
XmlElement node = (XmlElement)doc.SelectSingleNode("//map:properties", nsmgr);
node.SetAttribute("url", FilePath);
doc.Save(FilePath);