用什么控件能把一个XML文件的数据输出成如下格式.
<Nav>
<Root Title= "AAA ">
<Item href= "111 "> X1 </Item>
<Item href= "111 "> X2 </Item>
<Item href= "111 "> X3 </Item>
</Root>
<Root Title= "BBB ">
<Item href= "111 "> Y1 </Item>
<Item href= "111 "> Y2 </Item>
<Item href= "111 "> Y3 </Item>
</Root>
<Root Title= "CCC ">
<Item href= "111 "> Z1 </Item>
<Item href= "111 "> Z2 </Item>
<Item href= "111 "> Z3 </Item>
</Root>
</Nav>
我自己建的一个XML 目的是为了存储一个二级分类或导航.可能不合理请指出.
要输出如下格式.就是一个NAVBAR
AAA (这个是标题点击会展开)
X1(这个是链接)
X2
X3
BBB
Y1
Y2
Y3
CCC
Z1
Z2
Z3
用哪个控件可以实现??repeater dateview datelist 应该怎么实现.谢谢.
------解决方案--------------------repeater 嵌套.
------解决方案--------------------用treeview最简单了.
------解决方案--------------------string str = @ " <Nav>
<Root Title= " "AAA " ">
<Item href= " "111 " "> X1 </Item>
<Item href= " "111 " "> X2 </Item>
<Item href= " "111 " "> X3 </Item>
</Root>
<Root Title= " "BBB " ">
<Item href= " "111 " "> Y1 </Item>
<Item href= " "111 " "> Y2 </Item>
<Item href= " "111 " "> Y3 </Item>
</Root>
<Root Title= " "CCC " ">
<Item href= " "111 " "> Z1 </Item>
<Item href= " "111 " "> Z2 </Item>
<Item href= " "111 " "> Z3 </Item>
</Root>
</Nav>
";
XmlDocument dom = new XmlDocument();
dom.LoadXml(str);
XmlNodeList nl = dom.SelectNodes( "//Root ");
foreach (XmlNode node in nl)
{
TreeNode tn = new TreeNode();
tn.Text = node.Attributes[ "Title "].Value;
TreeView1.Nodes.Add(tn);
foreach (XmlNode cNode in node.ChildNodes)
{
TreeNode cTn = new TreeNode();
cTn.Text = cNode.InnerText;
cTn.NavigateUrl = cNode.Attributes[ "href "].Value;
tn.ChildNodes.Add(cTn);
}
}