什么是生成xml文件的最佳方法

时间:2010-11-17 05:08:21

标签: c# .net

  

可能重复:
  What is the best way to build XML in C# code?

生成xml文件的最佳方法是什么?

1 个答案:

答案 0 :(得分:1)

在.Net

中使用XmlWriter
        var writerSettings = new XmlWriterSettings();
        writerSettings.Indent = true;

        XmlWriter writer = XmlWriter.Create("d:\\MyFirstXmlFile.xml", writerSettings);

        writer.WriteStartDocument();
        writer.WriteStartElement("People");

        writer.WriteStartElement("Person");
        writer.WriteElementString("Name", "Zain Shaikh");
        writer.WriteElementString("JobDescription", "Software Engineer");
        writer.WriteElementString("Facebook", "http://www.facebook.com/zainshaikh");
        writer.WriteEndElement();

        writer.WriteEndElement();
        writer.WriteEndDocument();

        writer.Flush();