net使用xml操作菜单(站点地图)
其实webmap文件可以快速的管理站点地图,但是不方便网站站点的全局管理,因此,使用XML来操作站点地图。看菜单的XML文件代码:
<?xml version="1.0" encoding="utf-8"?> <guided> <name hreaf="http://www.baidu.com" id="1">首页</name> <name hreaf="http://www.baidu.com" id="2">xxx</name> <name hreaf="http://www.baidu.com" id="3">xxx</name> <name hreaf="http://www.baidu.com" id="4">xxx</name> <name hreaf="http://www.baidu.com" id="5">xxx</name> <name hreaf="http://www.baidu.com" id="6">xxx</name> <name hreaf="http://www.baidu.com" id="7">xxx</name> </guided>
当然这只是定义了网站的访问路径,我们还需要在web页面中添加相应的代码。如:
protected void Semue() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Server.MapPath("../xml/guided.xml")); XmlNode xn = xmlDoc.SelectSingleNode("guided"); XmlNodeList xnl = xn.ChildNodes; List<guided> po = new List<guided>(); foreach (XmlNode xml in xnl) { guided pos = new guided(); XmlElement xe = (XmlElement)xml; pos.Id = xe.GetAttribute("id"); pos.Hreaf = xe.GetAttribute("hreaf"); XmlNodeList xnl0 = xe.ChildNodes; pos.Name = xnl0.Item(0).InnerText; po.Add(pos); } xmlDoc.Clone(); list5 = po; } protected List<guided> list5 { get; set; }
在添加这个的时候,要主要引用Using system.xml;之后就是aspx文件代码的绑定
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <div id="templatemo_header_wrapper"> 2 <div id="templatemo_header"> 3 <div class="main"> 4 <div id="Right_top"> 5 <table cellpadding="0" cellspacing="0"> 6 <tr> 7 <td width="22px"> 8 <div> 9 <img src="../images/1.png" /> 10 </div> 11 </td> 12 <td width="40px"> 13 <a href="#">登录</a> 14 </td> 15 <td width="22px"> 16 <div> 17 <img src="../images/2.png" /> 18 </div> 19 </td> 20 <td width="40px"> 21 <a href="#">注册</a> 22 </td> 23 <td width="22px"> 24 <div> 25 <img src="../images/3.png" /> 26 </div> 27 </td> 28 <td width="70px"> 29 <a href="#">加入收藏</a> 30 </td> 31 <td width="22px"> 32 <div> 33 <img src="../images/4.png" /> 34 </div> 35 </td> 36 <td width="70px"> 37 <a href="#">设为首页</a> 38 </td> 39 </tr> 40 </table> 41 </div> 42 <div id="dao"> 43 <ul> 44 <%for (int i = 0; i < list5.Count; i++) 45 { %> 46 <li><a href="<%=list5[i].Hreaf %>"> 47 <%=list5[i].Name %></a></li> 48 <%} %> 49 </ul> 50 </div> 51 </div> 52 </div> 53 </div>
嗯,到这里就结束了哈。。。看懂了米?
风雨苦痛皆营养,欲成大木柱天长。