I want to creat this XML file with C# or ASP
- <?xml version="1.0" standalone="yes"?>
-
<Info>
-
<News>
-
<Item>
-
<Id>1</Id>
-
<Title>Test1</Title>
-
<Body>testing1 testing1 testing1</Body>
-
</Item>
-
<Item>
-
<Id>2</Id>
-
<Title>Test2</Title>
-
<Body>testing2 testing2 testing2</Body>
-
</Item>
-
<Item>
-
<Id>3</Id>
-
<Title>Test3</Title>
-
<Body>testing3 testing3 testing3</Body>
-
</Item>
-
</News>
-
<Press>
-
<Item>
-
<Id>1</Id>
-
<Title>t1</Title>
-
</Item>
-
<Item>
-
<Id>2</Id>
-
<Title>t2</Title>
-
</Item>
-
</Press>
-
</Info>
I have done this:
- using System;
-
using System.Collections;
-
using System.Configuration;
-
using System.Data;
-
using System.Web;
-
using System.Web.Security;
-
using System.Web.UI;
-
using System.Web.UI.HtmlControls;
-
using System.Web.UI.WebControls;
-
using System.Web.UI.WebControls.WebParts;
-
using System.IO;
-
using System.Xml;
-
using System.Xml.Schema;
-
using System.Xml.Serialization;
-
-
namespace test6
-
{
-
public partial class _Default : System.Web.UI.Page
-
{
-
DataSet ds = new DataSet("Info");
-
DataTable dt = new DataTable("News");
-
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
DataColumn dc = new DataColumn("ID");
-
DataColumn dc1 = new DataColumn("Title");
-
-
dt.Columns.Add(dc);
-
dt.Columns.Add(dc1);
-
-
dt.Merge(dt);
-
ds.Tables.Add(dt);
-
-
}
-
-
protected void Button1_Click(object sender, EventArgs e)
-
{
-
test();
-
}
-
-
private void test()
-
{
-
-
DataRow dr = ds.Tables["News"].NewRow();
-
dr["ID"] = TextBox1.Text;
-
dr["Title"] = TextBox2.Text;
-
ds.Tables["News"].Rows.Add(dr);
-
ds.WriteXml(Server.MapPath(Request.ApplicationPath) + "DB.xml");
-
Label1.Text = "testing testing testing";
-
-
}
-
-
}
-
}
but the Result is:
- <?xml version="1.0" standalone="yes"?>
-
<Info>
-
<News>
-
<ID>1</ID>
-
<Title>d</Title>
-
</News>
-
</Info>
I know that one of the problems is that everytime that I run the the code, a new table will be created so that a new table with new data will be replaced to the file
what can I do to creat that xml file?