<Flows><Flow Name=""测试流程-3"" FlowKey=""cslc"" Description="""">
<Step Stepid=""1"" Name=""流程环节1"" TaskType=""StartTask""><ForStep>0</ForStep><Nextstep>2</Nextstep><ExecutState>F</ExecutState><IsAllowSelectUser>T</IsAllowSelectUser><Executes><Exceute><ExecutorName></ExecutorName><ExecutorNo></ExecutorNo><ExecutorAuthority /></Exceute></Executes></Step><Step Stepid=""2"" Name=""流程环节2"" TaskType=""NormalTask""><ForStep>1</ForStep><Nextstep>3</Nextstep><ExecutState>F</ExecutState><IsAllowSelectUser>F</IsAllowSelectUser><Executes><Exceute><ExecutorName>张三</ExecutorName><ExecutorNo>01677</ExecutorNo><ExecutorAuthority /></Exceute></Executes></Step><Step Stepid=""3"" Name=""流程环节3"" TaskType=""NormalTask""><ForStep>2</ForStep><Nextstep>4</Nextstep><ExecutState>F</ExecutState><IsAllowSelectUser>T</IsAllowSelectUser><Executes><Exceute><ExecutorName></ExecutorName><ExecutorNo></ExecutorNo><ExecutorAuthority /></Exceute></Executes></Step></Flow></Flows></DataStore>"请问如何在以上XML结构的流程环节1 和流程环节3 插入人员信息(ExecutorName、ExecutorNo)?即以下红色标记的内容:
<Flows><Flow Name=""测试流程-3"" FlowKey=""cslc"" Description="""">
<Step Stepid=""1"" Name=""流程环节1"" TaskType=""StartTask""><ForStep>0</ForStep><Nextstep>2</Nextstep><ExecutState>F</ExecutState><IsAllowSelectUser>T</IsAllowSelectUser><Executes><Exceute><ExecutorName>李四</ExecutorName><ExecutorNo>01254</ExecutorNo><ExecutorAuthority /></Exceute></Executes></Step><Step Stepid=""2"" Name=""流程环节2"" TaskType=""NormalTask""><ForStep>1</ForStep><Nextstep>3</Nextstep><ExecutState>F</ExecutState><IsAllowSelectUser>F</IsAllowSelectUser><Executes><Exceute><ExecutorName>张三</ExecutorName><ExecutorNo>01677</ExecutorNo><ExecutorAuthority /></Exceute></Executes></Step><Step Stepid=""3"" Name=""流程环节3"" TaskType=""NormalTask""><ForStep>2</ForStep><Nextstep>4</Nextstep><ExecutState>F</ExecutState><IsAllowSelectUser>T</IsAllowSelectUser><Executes><Exceute><ExecutorName>王五</ExecutorName><ExecutorNo>01363</ExecutorNo><ExecutorAuthority /></Exceute></Executes></Step></Flow></Flows></DataStore>"

解决方案 »

  1.   

    已知有一个XML文件(bookstore.xml)如下:   
        
      <?xml   version="1.0"   encoding="gb2312"?>   
      <bookstore>   
          <book   genre="fantasy"   ISBN="2-3631-4">   
              <title>Oberon's   Legacy</title>   
              <author>Corets,   Eva</author>   
              <price>5.95</price>   
          </book>   
      </bookstore>   
          1、往<bookstore>节点中插入一个<book>节点:   
        
                
        
      XmlDocument   xmlDoc=new   XmlDocument();   
            xmlDoc.Load("bookstore.xml");   
            XmlNode   root=xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>   
            XmlElement   xe1=xmlDoc.CreateElement("book");//创建一个<book>节点   
            xe1.SetAttribute("genre","李赞红");//设置该节点genre属性   
            xe1.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性   
          
            XmlElement   xesub1=xmlDoc.CreateElement("title");   
            xesub1.InnerText="CS从入门到精通";//设置文本节点   
            xe1.AppendChild(xesub1);//添加到<book>节点中   
            XmlElement   xesub2=xmlDoc.CreateElement("author");   
            xesub2.InnerText="候捷";   
            xe1.AppendChild(xesub2);   
            XmlElement   xesub3=xmlDoc.CreateElement("price");   
            xesub3.InnerText="58.3";   
            xe1.AppendChild(xesub3);   
          
            root.AppendChild(xe1);//添加到<bookstore>节点中   
            xmlDoc.Save("bookstore.xml");   
      

  2.   

    我现在是要在已有节点下插入子节点的内容哦
    ------------------------------------
    非得一条一条写出来吗?不是已经告诉你创建节点.添加节点内容跟属性了吗?你获取节点之后用appendchild都不会吗?
      

  3.   

    目前对xml文档的操作不是很熟练,不过可以用另一种方法实现,先将此xml文件的内容存入一个dataSet中,然后遍历dataRow,这样你就能够修改了,等到你修改完了,然后在writeXML就行了,你要的效果肯定是能够实现的.也不是很麻烦啊 
      

  4.   

    可以用DOM+Xpath技术, 不用全部遍历
      

  5.   

    C#处理XMLhttp://dev.csdn.net/author/kingjiang/cd9a3c8136214b0a82b078ce16be3b25.html
      

  6.   

    我的XML结构是从SQL数据库读出来的修改之后要写入SQL中哪位高手有实践经验 麻烦传授下哦
      

  7.   

    XmlDocument doc = new XmlDocument();
    doc.LoadXml(strXml);XmlNodeList steps = doc.SelectNodes("/DataStore/Flows/Flow[@FlowKey='cslc']/Step");
    foreach(XmlNode step in steps)
    {
        if (step.Attributes["Name"] == "流程环节1")
        {
            SetNameAndNoInfo(step,"你要改的Name","你要改的No");    
        }
        if (step.Attributes["Name"] == "流程环节3")
        {
            SetNameAndNoInfo(step,"你要改的Name","你要改的No");    
        }
    }
    string outerXML = doc.OuterXml;
    //把这个字符串传到数据库就OK~~~~~private void SetNameAndNoInfo(XmlNode step,string name,string no)
    {
        XmlNode node1 = step.SelectSingleNode("Executes/Exceute/ExecutorName");    
        node1.InnerText = name;    
        XmlNode node2 = step.SelectSingleNode("Executes/Exceute/ExecutorNo"); 
        node2.InnerText = no;    
    }这些基本的操作可以参考MSDN就可以了~~~~~