C#如何创建一个XML文件 格式是 <A> <B C="D">E</B> </A>
1个回答
展开全部
System.Xml.XmlDocument xml = new System.Xml.XmlDocument();
System.Xml.XmlDeclaration dec = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
xml.AppendChild(dec);
System.Xml.XmlElement ele = xml.CreateElement("A");
xml.AppendChild(ele);
System.Xml.XmlElement ele2 = xml.CreateElement("B");
System.Xml.XmlAttribute xa = xml.CreateAttribute("C");
xa.Value = "D";
ele2.Attributes.Append(xa);
ele2.InnerXml= "E";
ele.AppendChild(ele2);
xml.Save(Server.MapPath("~/1.xml"));
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询