110,499
社区成员
发帖
与我相关
我的任务
分享
//代码如下:正常运行,就是添加到xml里后,显示没有 "</PlugInFile>"
try
{
string path = Application.StartupPath + (@"\PlugIn.xml");
XmlDocument doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.SelectSingleNode("PlugIn/PlugInConfig");
if (node == null)
return;
XmlElement ent = doc.CreateElement("PlugInFile");
ent.SetAttribute("text", 123);
ent.SetAttribute("ImpementInterface", 123);
ent.SetAttribute("ClassName", 123);
// XmlElement notexml = doc.CreateElement("Note");
// notexml.InnerText = this.txtnote.Text;
// node.AppendChild(notexml);
node.AppendChild(ent);
doc.Save(path);
MessageBox.Show("YES");
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
<?xml version="1.0" encoding="utf-8"?>
<PlugIn>
<PlugInConfig>
<PlugInFile text="JiangGuoLiang" ImpementInterface="001" ClassName="002" /> //这里没有 </PlugInFile>
<PlugInFile text="123" ImpementInterface="123" ClassName="123" /> //这里没有 </PlugInFile>
<PlugInFile text="456" ImpementInterface="456" ClassName="456" /> //这里没有 </PlugInFile>
</PlugInConfig>
</PlugIn>
private string path = Application.StartupPath + (@"\PlugIn.xml");
private XmlDocument doc = null;
private void button1_Click(object sender, EventArgs e)
{
try
{
doc = new XmlDocument();
doc.Load(path);
XmlNode node = doc.SelectSingleNode("PlugIn/PlugInConfig");
if (node == null)
return;
XmlElement xmle = doc.CreateElement("PlugInFile");
xmle.SetAttribute("text", "!@#");
xmle.SetAttribute("namespace","345");
node.AppendChild(xmle);
doc.AppendChild(node);
doc.Save(path);
MessageBox.Show("YES");
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
}