日期:2014-05-18 浏览次数:20459 次
<Root ID="OSMS" > <node ID="SMCG" Text="公告管理" ImageUrl="images/info.gif" Expanded="true" src="#"> <node ID="CGXXGL" Text="发部公告" ImageUrl="images/info.gif" src="Public Notice/PublicNotice_Add.aspx" /> <node ID="XSXXGL" Text="删除公告" ImageUrl="images/info.gif" src="Public Notice/PublicNotice_Del.aspx" /> <node ID="XSXXGL" Text="编辑公告" ImageUrl="images/info.gif" src="Public Notice/PublicNoticeEdit.aspx" /> <node ID="XSXXGL" Text="查询公告" ImageUrl="images/info.gif" src="Public Notice/PublicNoticeView.aspx" /> <node> [code=C#]
private void BuildTree()
{
tree_fromXML(Server.MapPath("ManageTree.xml"));
}
private void tree_fromXML(string XMLpath)
{
System.Xml.XmlDocument document = new System.Xml.XmlDataDocument();
document.Load(XMLpath); //xml文件加载到内存
Build_tree(document.DocumentElement, MyTreeView.Nodes);
}
private void Build_tree(System.Xml.XmlNode document, TreeNodeCollection nodes)
{
foreach (System.Xml.XmlNode node in document.ChildNodes)
{
if (node.Attributes["ID"].Value=="OSMS")
{
if (node.FirstChild.Attributes["ID"].Value == "SMCG")
{
TreeNode new_child = new TreeNode();
new_child.Text = node.FirstChild.Attributes["Text"].Value;
if (node.FirstChild.Attributes["ImageUrl"] != null && node.FirstChild.Attributes["ImageUrl"].Value != "")
new_child.ImageUrl = node.FirstChild.Attributes["ImageUrl"].Value;
if (node.FirstChild.Attributes["src"].Value.Trim() != "#")
{
//new_child.Target = "frameColumn";
new_child.NavigateUrl = node.FirstChild.Attributes["src"].Value;
&n