if following is your infor.xml ( suppose it located in root directory of disk C)
<?xml version="1.0" encoding="utf-8"?>
<Root>
<person>
<name>pie</name>
<E_mail>[email protected]</E_mail>
<address>xmu</address>
</person>
</Root> XmlDocument doc;
doc=new XmlDocument();
doc.Load(@"c:\Infor.XML"); XmlElement rootElement=doc.DocumentElement; XmlElement newChild;
XmlElement newChild2;
XmlElement newChild3;
XmlElement newChild4;
newChild= doc.CreateElement("person"); // <person>
//<name>pie</name>
//<E_mail>[email protected]</E_mail>
//<address>xmu</address>
//</person>
newChild2=doc.CreateElement("name");
newChild2.InnerText="pie";
newChild3=doc.CreateElement("E_mail");
newChild3.InnerText="[email protected]";
newChild4=doc.CreateElement("address");
newChild4.InnerText="xmu";
newChild.AppendChild(newChild2);
newChild.AppendChild(newChild3);
newChild.AppendChild(newChild4); rootElement.AppendChild(newChild);
doc.Save(@"c:\Infor.XML");
<?xml version="1.0" encoding="utf-8"?>
<Root>
<person>
<name>pie</name>
<E_mail>[email protected]</E_mail>
<address>xmu</address>
</person>
</Root> XmlDocument doc;
doc=new XmlDocument();
doc.Load(@"c:\Infor.XML"); XmlElement rootElement=doc.DocumentElement; XmlElement newChild;
XmlElement newChild2;
XmlElement newChild3;
XmlElement newChild4;
newChild= doc.CreateElement("person"); // <person>
//<name>pie</name>
//<E_mail>[email protected]</E_mail>
//<address>xmu</address>
//</person>
newChild2=doc.CreateElement("name");
newChild2.InnerText="pie";
newChild3=doc.CreateElement("E_mail");
newChild3.InnerText="[email protected]";
newChild4=doc.CreateElement("address");
newChild4.InnerText="xmu";
newChild.AppendChild(newChild2);
newChild.AppendChild(newChild3);
newChild.AppendChild(newChild4); rootElement.AppendChild(newChild);
doc.Save(@"c:\Infor.XML");
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货