日期:2014-05-18  浏览次数:20788 次

查找,修改xml节点的属性
<?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 "


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

------解决方案--------------------
硬编码

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