xml修改
有一段xml文件:
<?xml version="1.0" encoding="GBK"?>
<slider>
<item href="#/" title="我院召开大学生艺术展演协调会" imageurl="images/01.jpg"> </item>
<item href="#/" title="排解心理困惑 辅导艺术技能" imageurl="images/02.jpg" ></item>
<item href="#/" title="大学生如何开展科研立" imageurl="images/03.jpg"> </item>
<item href="#/" title="“知心姐姐”牵手瓯海丽岙侨乡留守儿童" imageurl="images/04.jpg"> </item>
</slider>
现在需要在.cs文件中进行修改,item 项都要用数据库中的内容修改掉。本人未学过xml,故求各位帮忙看下,不胜感激!
修改方式为:从数据库中读取linkArray[i] ,txtArray[i],urlArray[i],分别对应xml文件中的href,title,imageurl。
private void getArticle()
{
protected System.Data.SqlClient.SqlConnection SqlConnection1;
protected System.Data.SqlClient.SqlCommand SqlCommand1;
protected System.Data.SqlClient.SqlDataReader SqlDataReader1;
public int[] linkArray = new int[4];
public string[] txtArray = new string[4];
public string[] urlArray = new string[4];
SqlConnection1 = new SqlConnection(ConfigurationSettings.AppSettings["dsn"]);
SqlCommand1 = new SqlCommand("select top 4 * from tlx_news where pic is not null and pic<>" + "''" + " and (type='通知公告' or type='课程资讯') order by postTime desc", SqlConnection1);
try
{
SqlConnection1.Open();
SqlDataReader1 = SqlCommand1.ExecuteReader();
}
catch (SqlException e1)
{
Response.Write("数据操作错误:" + e1.Message);
}
int i = 0;
while (SqlDataReader1.Read() == true)
{
linkArray[i] = SqlDataReader1.GetInt32(0);
txtArray[i] = SqlDataReader1.GetString(1);
urlArray[i] = SqlDataReader1.GetString(7).ToString().Trim();
++i;
}
SqlConnection1.Close(); //why?
}
现在问题是怎么修改xml文件?望会的给出代码或提示,谢谢!
[解决办法]
漏了一个定义:
XmlElement xe=(XmlElement)xnl[i]
----------------
while (i < xnl.length){
XmlElement xe=(XmlElement)xnl[i]
xe.setAttribute("href",linkArray[i])
xe.setAttribute("title",txtArray[i])
xe.setAttribute("imageurl",urlArray[i])
}