目的:取出某个section下的所有game,并将game的内容绑定到repeater控件
game.xml(文件太长,其中games下包含多个section,每个section下有多个game,所以只放这里一个game节点,这样设计有问题?):
<?xml version="1.0" encoding="gb2312" ?>
<games xmlns="http://tempuri.org/game.xsd">
<section sectionname="百科知识馆" listfile="index.aspx">
<game>
<gamename>我猜我猜我猜猜猜</gamename>
<smallpic>game14x.jpg</smallpic>
<bigpic>game14.jpg</bigpic>
</game>
</section>
</games>
x.aspx(不知道访问xml这样的思路对不对?):
string xmlpath=Server.MapPath("/xml/game.xml");
XPathDocument doc=new XPathDocument(xmlpath);
XPathNavigator nav=doc.CreateNavigator();
XPathNodeIterator iter=nav.Select("/games/section[@sectionname='百科知识馆']/game");
game.xml(文件太长,其中games下包含多个section,每个section下有多个game,所以只放这里一个game节点,这样设计有问题?):
<?xml version="1.0" encoding="gb2312" ?>
<games xmlns="http://tempuri.org/game.xsd">
<section sectionname="百科知识馆" listfile="index.aspx">
<game>
<gamename>我猜我猜我猜猜猜</gamename>
<smallpic>game14x.jpg</smallpic>
<bigpic>game14.jpg</bigpic>
</game>
</section>
</games>
x.aspx(不知道访问xml这样的思路对不对?):
string xmlpath=Server.MapPath("/xml/game.xml");
XPathDocument doc=new XPathDocument(xmlpath);
XPathNavigator nav=doc.CreateNavigator();
XPathNodeIterator iter=nav.Select("/games/section[@sectionname='百科知识馆']/game");
解决方案 »
- winform datagirdview绑定问题
- string.indexof和集合的contains哪个更快
- VS 调试时输出窗口显示的异常 来着有分~~
- 往存储过程传参时发生的错误
- 在控件中动态加载控件事件丢失
- 一个查询条件中含有多个值,怎么传到存储过程中再查询含有这几个值的记录?
- 串口数据显示在textbox里有问题
- 跪求如何在聊天室中显示在线人员情况?急急!!!
- 更新excel问题。
- Winform treeview 点击子节点跳转窗体弹出两个窗体
- ********!sqlBinary怎么转换成byte[]!********
- 在winform中怎样把datatable中某一列的数据用datagrid显示出来?
DataSet ds=new DataSet();
ds.ReadXml(Server.MapPath("/xml/game.xml"));
this.repeater1.DataSource=ds.Tables["section"];
this.repeater1.DataBind();
比如我有三个二级节点,六个三级节点,每个二级节点有两个三级节点,
但生成的dataset中竟然只有两个表,一个section,一个game,
game表六条数据六个三级节点,section三条数据三个二级节点,
而我想要的是三个section表,各自有两条game记录
node就是section节点
foreach(XmlNode n in node.Nodes)
{
//你可以得到每个game}
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("games/section[@sectionname='百科知识馆']");
foreach (XmlNode node in nodeList)
{
//每个section的node
}