生成xml
<items>
<item Text= "News " NavigateUrl= "WebForm1.aspx " DefaultSubItemLookId= "Level2Tab " DefaultSubItemSelectedLookId= "SelectedLevel2Tab " >
<item Text= "Top Stories " NavigateUrl= "WebForm1.aspx?page=top_stories " />
<item Text= "Breaking News " NavigateUrl= "WebForm1.aspx?page=breaking_news " />
<item Text= "World News " NavigateUrl= "WebForm1.aspx?page=world_news " />
</item>
</items>
请问怎么生成呢??其中News,Markets,Travel,Travel2006从数据库读出,又由News读出下面的 <item Text= "News " NavigateUrl= "WebForm1.aspx " DefaultSubItemLookId= "Level2Tab " DefaultSubItemSelectedLookId= "SelectedLevel2Tab " >
<item Text= "Top Stories " NavigateUrl= "WebForm1.aspx?page=top_stories " />
<item Text= "Breaking News " NavigateUrl= "WebForm1.aspx?page=breaking_news " />
<item Text= "World News " NavigateUrl= "WebForm1.aspx?page=world_news " />
</item>
------解决方案-------------------- DataTable dt=查询的数据;
//根据News,Markets,Travel,Travel2006条件判断循环的拼字符串
string s= " ";
for(int i=0;i <dt.Rows.Count;i++ )
{
if(dt.Rows[i][ "new "].ToString()== "new ")
{
s+= " <item> + ";
s+= " <item Text= "+News+ " ... > + ";
s+= "...+ ";
s+= "...+ ";
s+= " </item> ";
}
if(dt.Rows[i][ "Markets "]== "Markets ")
{
s+= " <item> + ";
s+= " <item Text= "+Markets+ " ... > + ";
s+= "...+ ";
s+= "...+ ";
s+= " </item> ";
}
...
...
}
//用io写xml
StreamWriter sw=new StreamWriter( Server.MapPath( " ")+ "/ "+filename+ ".xml ",false,System.Text.Encoding.GetEncoding( "GB2312 "));
sw.Write(s);
sw.Close();
------解决方案--------------------参照select ... for xml语法。