zoukankan      html  css  js  c++  java
  • System.Xml.XmlDocument 例子

    using System.Xml;
    public
    class SiteMapHelper { public List<UrlModel> GetImagesInfo(string requestPath) { List<UrlModel> list = new List<UrlModel>(); string[] parms = requestPath.Split('/'); if (parms[1] != null && parms[2] != null) { //当前模块 string currentModel = parms[1]; //当前页面 string currentPage = parms[2]; ImageUrl model = new ImageUrl(); string xmlFilePath = HttpContext.Current.Server.MapPath("~/Config/SiteMapSetting.xml"); XmlDocument doc = new XmlDocument(); doc.Load(xmlFilePath); XmlNode xn = doc.SelectSingleNode("items"); XmlNodeList xnList = xn.ChildNodes; if (xnList.Count > 0) { foreach (XmlElement xe in xnList) { if (xe.Attributes["name"].Value.ToLower() == currentModel.ToLower()) { UrlModel url = new UrlModel(); url.Url = xe.Attributes["url"].Value; url.Name = xe.Attributes["show"].Value; url = this.ModuleUrlRewrite(currentModel,url); list.Add(url); XmlNodeList allSubNodes = xe.ChildNodes; if (allSubNodes.Count > 0) { foreach (XmlElement item in allSubNodes) { if (item.Attributes["name"].Value.Equals(currentPage, StringComparison.CurrentCultureIgnoreCase)) { url = new UrlModel(); url.Url = currentPage; url.Name = item.Attributes["show"].Value; list.Add(url); } } } } } } return list; } return null; } /// <summary>模块url特殊情况的,如请求Login/Xxx.aspx 其SiteMap分组URL转成Company分组 /// </summary> /// <param name="moduleName">模块名</param> /// <param name="url">当前URL模型</param> /// <returns></returns> private UrlModel ModuleUrlRewrite(string moduleName, UrlModel url) { if (moduleName.Equals("login", StringComparison.CurrentCultureIgnoreCase)) { url.Url = "/Company/" + url.Url; } return url; } } public class UrlModel { private string _name; public string Name { get { return _name; } set { _name = value; } } private string _url; public string Url { get { return _url; } set { _url = value; } } }
    SiteMapSetting.xml
    <?xml version="1.0" encoding="utf-8" ?>
    <items>
      <model name="Company" url="EmploreeList.aspx" show="基础设置">
        <page name="EmploreeList.aspx" show="人才库" />
      </model>
      <model name="Login" url="EmploreeList.aspx" show="基础设置">
        <page name="Zuzhijiagou.aspx" show="组织架构" />
      </model>
      <model name="ModelManage" url="TaskList.aspx" show="智能建模">
        <page name="TaskList.aspx" show="模型列表" />
        <page name="Step1.aspx" show="提交建模需求" />
        <page name="UnfinTaskList.aspx" show="填写建模问卷" />
        <page name="LatChoice.aspx" show="调整能力模型"></page>
      </model>
      <model name="AbilityAccess" url="DoneProject.aspx" show="多源反馈">
        <page name="DoneProject.aspx" show="评估列表" />
        <page name="SucessorFirst.aspx" show="接班人计划" />
        <page name="SucessorSecond.aspx" show="接班人计划" />
      </model>
      <model name="PersonTest" url="FinishPos.aspx" show="定制选才">
        <page name="PositionTest.aspx" show="岗位招聘" />
        <page name="FinishPos.aspx" show="测评列表" />
      </model>
      <model name="AbilityTeam" url="DoneProject.aspx" show="团队竞争力">
        <page name="DoneProject.aspx" show="团队项目列表" />
      </model>
      <model name="PersonHome" url="Xxx.aspx" show="个人中心">
        <page name="OnlineQuestionList.aspx" show="咨询记录" />
        <page name="ChangePwd.aspx" show="修改密码" />
      </model>
      <model name="TrainingPlan" url="TrainingCourseList.aspx" show="培训规划">
      <page name="TrainingCourseList.aspx" show="课表检索" />
      </model>
    </items>
  • 相关阅读:
    hibernate4 无法保存 不报错
    win10开启mongodb 开启服务
    nodejs学习笔记
    mariadb Too many connections
    新老ECS数据库速度对比
    数据库自动备份并打成tar.gz包
    字符串和数组----string
    I/O复用(select)——回声服务器端/客户端
    回声UDP服务器端/客户端
    回声TCP服务器端/客户端
  • 原文地址:https://www.cnblogs.com/zhuji/p/12192178.html
Copyright © 2011-2022 走看看