日期:2014-05-19  浏览次数:20825 次

求利用C#创建一个XML并保存到XML文件中的代码
要求如下:创建一个叫abc.xml的文档,然后根节点叫root,在根结点下创建一个 <a> 结点, <a> 节点有个b属性,属性值是123,然后把这个xml文档保存到文件中。

------解决方案--------------------

XmlTextWriter myWriterxsl = new XmlTextWriter(@ "E:\testxsl.xml ", Encoding.UTF8);
myWriterxsl.Formatting = Formatting.Indented;
myWriterxsl.WriteStartDocument();

myWriterxsl.WriteStartElement( " ", "root ", " ");
myWriterxsl.WriteStartElement( " ", "a ", " ");
myWriterxsl.WriteAttributeString( "b ", "123 ");
myWriterxsl.WriteEndElement();
myWriterxsl.WriteEndDocument();
myWriterxsl.Flush();
myWriterxsl.Close();
------解决方案--------------------
http://www.pconline.com.cn/pcedu/empolder/net/0406/388296.html
------解决方案--------------------
需要用到XmlNode和XmlAttribute两个类