xml格式的问题
XmlDocument myDoc = new XmlDocument();
//加载XML文件
myDoc.Load(FileName);
XmlTextWriter xtw = new XmlTextWriter(System.Web.HttpContext.Current.Server.MapPath("bcastr.xml"), Encoding.UTF8);//xml的生成路径
xtw.Formatting = Formatting.Indented;
xtw.WriteStartDocument();
xtw.WriteStartElement("pie"); //节点 == topStories
//xtw.WriteAttributeString("autoPlayTime", "6");
string strSql = "SELECT * from dbo.Table_12";
DataSet ds = db.dataSet(strSql);
int max = ds.Tables[0].Rows.Count;
for (int i = 0; i < max; i++)
{
if (ds.Tables[0].Rows[i]["photo"].ToString().Trim() == string.Empty)
{
continue;
}
xtw.WriteStartElement("slice");//==story1
xtw.WriteAttributeString("title",ds.Tables[0].Rows[i]["photo"].ToString());//== imageURL
xtw.WriteEndElement();
}
xtw.WriteFullEndElement();
xtw.Close();
生成的是
<?xml version="1.0" encoding="utf-8" ?>
- <pie>
<slice title="111" />
<slice title="222" />
<slice title="333" />
<slice title="444" />
</pie>
但是我想要
<?xml version="1.0" encoding="utf-8" ?>
-<pie>
<slice title="111">19544</slice>
<slice title="222">154</slice>
</pie>
------解决方案--------------------
xtw.WriteAttributeString("title",ds.Tables[0].Rows[i]["photo"].ToString());//== imageURL
xtw.WriteString("xxxx");
xtw.WriteEndElement();