<?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"

解决方案 »

  1.   

    Xmldocument doc = new Xmldocument();
    doc.Load(@"e:\1.xml");XmlElement node = (XmlElement)doc.SelectSingleNode("//properties");
    node.SetAttribute("url", @"E:\CRM");doc.Save(@"e:\1.xml");
      

  2.   

    参考 创建、查询、修改带名称空间的 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"
      

  3.   

    硬编码doc.ChildNodes[1].FirstChild.SetAttribute("url", @"E:\CRM");
      

  4.   

    XmlElement node = (XmlElement)doc.SelectSingleNode("//properties");
                    node.SetAttribute("url", FilePath);
    我调试时node =null
      

  5.   

    我调试时node =null
    --->
    你得象孟子说的那样带着命名空间~~~~
      

  6.   

    XmlDocument doc = new XmlDocument();
                    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);
    哪位大哥指点,这代码哪里有问题
      

  7.   

    命名空间问题,下面代码可以:XmlDocument doc = new XmlDocument();
                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");
      

  8.   

    改成楼上的就可以了,我以前没用命名空间怎么也可以啊!  
      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);