asp.net中xml的写入问题

来源:百度知道 编辑:UC知道 时间:2024/05/20 05:39:51
我要在xml中写成这个样子的~后台中怎么写入`~
<?xml version=\"1.0\" ?>
<img src="images/01.jpg" width="400" height="266" />
<img src="images/02.jpg" width="400" height="266" />
路径要在数据库中读取~
谢谢大家帮我解决下~~急啊~~
问题是如果要根目录的话,图片就读不出来啦~~能不能不要根目录写入~

void WriteXML()
{
SqlConnection con = new SqlConnection("ConnectionStringSettings");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("SQL", con);
DataSet ds = new DataSet();
sda.Fill(ds);
XmlTextWriter xtw = new XmlTextWriter(Server.MapPath("/") + "abc.xml", System.Text.Encoding.UTF8);
xtw.WriteStartDocument();
xtw.WriteStartElement("Root");//根元素...
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
xtw.WriteStartElement("img");
xtw.WriteAttributeString("width", "400"
xtw.WriteAttributeString("height","266"
xtw.WriteEndElement();
}
xtw.WriteEndElement();
xtw.WriteEndDocument();
xtw.Close();
con.Close();
}

没有根元素貌似不太规范
XmlWriterSettings xmlWS = new XmlWriterSettings();
xmlWS.CheckCharacters = true;
xmlWS.Indent