asp.net 生成xml问题。
分类,sImgRoute,dImgRoute,comment是从数据库读出的。SelectSingleNode menu ,没法区分。都生产到第一个了。要生产下面的怎么循环生产。谢谢!
<?xml version="1.0"?>
<category>
<menu title="分类1">
<img sImgRoute="thumb/img0.jpg" dImgRoute="image/img0.jpg" comment="简介bvbvb" />
<img sImgRoute="thumb/img1.jpg" dImgRoute="image/img1.jpg" comment="简介" />
<img sImgRoute="thumb/img2.jpg" dImgRoute="image/img2.jpg" comment="简介" />
<img sImgRoute="thumb/img3.jpg" dImgRoute="image/img3.jpg" comment="简介fdfdfd" />
</menu>
<menu title="分类2">
<img sImgRoute="thumb/img0.jpg" dImgRoute="image/img0.jpg" comment="简介bvbvb" />
<img sImgRoute="thumb/img1.jpg" dImgRoute="image/img1.jpg" comment="简介" />
<img sImgRoute="thumb/img2.jpg" dImgRoute="image/img2.jpg" comment="简介" />
</menu>
</category>
------解决方案--------------------没看懂,能不能详细些?
------解决方案--------------------楼主的意思是要写入<menu title="分类2">
<img sImgRoute="thumb/img0.jpg" dImgRoute="image/img0.jpg" comment="简介bvbvb" />
<img sImgRoute="thumb/img1.jpg" dImgRoute="image/img1.jpg" comment="简介" />
<img sImgRoute="thumb/img2.jpg" dImgRoute="image/img2.jpg" comment="简介" />
</menu> ???
循环数据库DataTable里的DataRow
------解决方案--------------------帮你顶
------解决方案--------------------
C# code
for (int j = 0; j < dt2.Rows.Count; j++)
{
if (dt.Rows[i]["style"].ToString() == dt2.Rows[j]["style"].ToString())
{
XmlNode menu = category.SelectNodes("menu").Item(j); // 用SelectNodes
XmlElement xe2 = xd.CreateElement("img");
xe2.SetAttribute("sImgRoute", dt2.Rows[j]["sImgRoute"].ToString());
xe2.SetAttribute("dImgRoute", dt2.Rows[j]["dImgRoute"].ToString());
xe2.SetAttribute("comment", dt2.Rows[j]["comment"].ToString());
menu.AppendChild(xe2);
}
}