xml新手问题,如何增加节点?
<SchedulerServer>
<AutoPrompt>
<PromptId>2</PromptId>
<PromptCycle>2</PromptCycle>
<PromptTime>0</PromptTime>
<LastTime></LastTime>
</AutoPrompt>
</SchedulerServer>
小弟刚会了读节点,和修改。
读:
XmlDocument xmldoc=new XmlDocument();
XmlNodeList xmlnd;strPath=System.Environment.SystemDirectory+@"\SchedulerServer.xml";
xmldoc.Load(strPath);
xmlnd=xmldoc.SelectNodes("SchedulerServer/AutoPrompt");
//arrConf=new String[2,xmlnd.Count];
string d="",t="";
for(int i=0;i<xmlnd.Count;i++) {
d=xmlnd[i].SelectSingleNode("PromptId").InnerXml.Trim();
t=xmlnd[i].SelectSingleNode("PromptCycle").InnerXml.Trim();
}
改:
XmlDocument xmldoc=new XmlDocument();
XmlNodeList xmlnd;
strPath=System.Environment.SystemDirectory+@"\SchedulerServer.xml";
xmldoc.Load(strPath);
xmlnd=xmldoc.SelectNodes("SchedulerServer/AutoPrompt");
XmlNode node = xmlnd[0].SelectSingleNode("PromptId");
if (node != null)
node.InnerXml = this.Date.SelectedItem.Value;
node = xmlnd[0].SelectSingleNode("PromptCycle");
if (node != null) node.InnerXml = this.Time.SelectedItem.Value;
xmldoc.Save(strPath);
那么小弟要加一个节点,和删除一个,怎么作呢??
<AutoPrompt>
<PromptId>1</PromptId>
<PromptCycle>12</PromptCycle>
<PromptTime>10</PromptTime>
<LastTime>ddd</LastTime>
</AutoPrompt>
请赐教!!