哪位大哥帮帮我怎么样写出这样格式的保存为XML文件啊?
<data>
      <new>
        <news id="1" title="..." time="..." />
      </new>
</data>

解决方案 »

  1.   

    using (StreamWriter sw = File.CreateText(fullfilepath))
                {
                    sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
                    sw.WriteLine("<data>");
                    
                    sw.WriteLine("\t<new>");
                    sw.Write("\t\t<news ");
                    sw.Write("id=\"1\" ");
                    sw.Write("title=\"1\"");
                    ....................
                    sw.WriteLine("\t\t</news>");
                    sw.WriteLine("\t</new>");
                    sw.WriteLine("</data>");
      

  2.   

    可以写成动态的吗?我是用DataSet获得数据 然后想写成这种格式
      

  3.   

    DataSet的Table里面的数据都是结构化的数据,它面完全可以可XML文档对应
    据个例子:
    news表:ID      Title           Content         DateTime
    1       11111           1111111         2007/08/24
    根据news表的结构使用C#代码 很容易生成下面的代码:
    <?xml version=\"1.0\" encoding=\"utf-8\" ?>
    <news>
     <new>
      <ID>1</ID>
      <Title>11111</Title>
      <Content>1111111</Content>
      <DateTime>2007/08/24</DateTime>
     </new>
     <new>
      ..........
      ..........
     </new>
    </news>
      

  4.   

    对呀。DateSet 可以真接生成 XML