<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>"
<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>"
<?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");
------------------------------------
非得一条一条写出来吗?不是已经告诉你创建节点.添加节点内容跟属性了吗?你获取节点之后用appendchild都不会吗?
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就可以了~~~~~