using System.Xml; XmlDocument xdTree = new XmlDocument(); xdTree.Load(Server.MapPath("~/TreeView.xml"));//读取XML文件 XmlElement xmlNew=xdTree.CreateElement("siteMapNode");//创建节点 xmlNew.SetAttribute("title",cate.Name); xmlNew.SetAttribute("url","BookList.aspx?typeid=1");//+cate.Id.ToString()); xmlNew.SetAttribute("description",""); xdTree.SelectSingleNode("siteMapNode").AppendChild(xmlNew);//将节点值添加到节点 xdTree.Save(Server.MapPath("~/TreeView.xml"));//保存XML文件
<?xml version="1.0" encoding="utf-8" ?> - <siteRoot Id="root" url="" title="管理员控制面板" description=""> - <siteMapNode url="" title="用户管理" description=""> <siteMapNode url="~AdminListAllUsers.aspx" title="管理用户" description="" /> <siteMapNode url="~AdminUserStatue.aspx" title="状态管理" description="" /> <siteMapNode url="~AdminListAllUsers.aspx" title="用户列表" description="" /> </siteMapNode> - <siteMapNode url="" title="图书分类管理" description=""> <siteMapNode url="~AdminAddBooksCatagory.aspx" title="添加图书分类" description="" /> <siteMapNode url="~AdminListBooksByCategory.aspx" title="为书籍分类" description="" /> <siteMapNode url="~AdminListOfBooks.aspx" title="书籍列表" description="" /> </siteMapNode> - <siteMapNode url="" title="定单管理" description=""> <siteMapNode url="~AdminCheckOrders.aspx" title="审核定单" description="" /> </siteMapNode> <siteMapNode url="~AdminLoginOut.aspx" title="退出" description="管理员退出" /> </siteRoot>