asp.net 循環讀取XML文檔

XML文檔格式如下

[xhtml] view plaincopy
  1. <?xml version="1.0" encoding="utf-8" ?>  
  2. <menu>  
  3.   <submenu id="1" text="校區基本信息">  
  4.     <item text="校區管理" href="SchoolBaseSet/SchoolManagement/SchoolInformation.aspx" mce_href="SchoolBaseSet/SchoolManagement/SchoolInformation.aspx" roles="超級管理員,系統管理員,院校長"></item>  
  5.     <item text="班級管理" href="SchoolBaseSet/ClassManagement/ClassInformation.aspx" mce_href="SchoolBaseSet/ClassManagement/ClassInformation.aspx" roles="超級管理員,系統管理員,班主任,院校長,教學主管,教學主任,校區考試專員" ></item>  
  6.     <item text="學生信息管理" href="SchoolBaseSet/StudentInformation/StudentInformation.aspx" mce_href="SchoolBaseSet/StudentInformation/StudentInformation.aspx" roles="超級管理員,系統管理員,院校長,班主任,教學主管,教學主任" ></item>  
  7.     <item text="用戶信息管理" href="SchoolBaseSet/UserManagement/UserInformation.aspx" mce_href="SchoolBaseSet/UserManagement/UserInformation.aspx" roles="超級管理員,系統管理員,院校長,教學主管,教學主任"></item>  
  8.     <item text="教師審批管理" href="SchoolBaseSet/TeacherPass/TeacherPass.aspx" mce_href="SchoolBaseSet/TeacherPass/TeacherPass.aspx" roles="教學主管,教學主任,校區考試專員"></item>  
  9.     <item text="切換教師角色" href="SchoolBaseSet/TeacherPass/RolesChange.aspx" mce_href="SchoolBaseSet/TeacherPass/RolesChange.aspx" roles="校區考試專員"></item>  
  10.   </submenu>  
  11.   
  12.   <submenu id="2" text="學生成績管理">  
  13. <item text="成績綜合管理" href="StudentGradeManagement/StudentGradedescirption/StudentGradeAll.aspx" mce_href="StudentGradeManagement/StudentGradedescirption/StudentGradeAll.aspx" roles="超級管理員,系統管理員,院校長,班主任,教學主管,教學主任" ></item>  
  14.   <item text="學生成績管理" href="StudentGradeManagement/StudentGradedescirption/StudentInformation.aspx" mce_href="StudentGradeManagement/StudentGradedescirption/StudentInformation.aspx" roles="超級管理員,系統管理員,院校長,班主任,教學主管,教學主任" ></item>  
  15.   </submenu>  
  16.   
  17.   <submenu id="3" text="數據字典設置">  
  18.     <item text="專業管理" href="DataDictionary/Specialty/Specialties.aspx" mce_href="DataDictionary/Specialty/Specialties.aspx" roles="超級管理員,系統管理員" ></item>  
  19.     <item text="課程管理" href="DataDictionary/Course/Courses.aspx" mce_href="DataDictionary/Course/Courses.aspx" roles="超級管理員,系統管理員" ></item>  
  20.     <item text="專業課程管理" href="DataDictionary/CourseInSpecialty/CouserInSpecialty.aspx" mce_href="DataDictionary/CourseInSpecialty/CouserInSpecialty.aspx" roles="超級管理員,系統管理員" ></item>  
  21.     <item text="角色管理" href="DataDictionary/Rolse/Roles.aspx" mce_href="DataDictionary/Rolse/Roles.aspx" roles="超級管理員"></item>  
  22.     <item text="管理員管理" href="DataDictionary/AdminUser/AdministratorUser.aspx" mce_href="DataDictionary/AdminUser/AdministratorUser.aspx" roles="超級管理員" ></item>  
  23.     <item text="Logo圖標管理" href="DataDictionary/Logo/EditLogo.aspx" mce_href="DataDictionary/Logo/EditLogo.aspx" roles="超級管理員,系統管理員,教學主管,教學主任" ></item>  
  24.     <item text="學號長度設置" href="DataDictionary/StudentCodeSet/StudentCodeLenghtInf.aspx" mce_href="DataDictionary/StudentCodeSet/StudentCodeLenghtInf.aspx" roles="超級管理員,系統管理員" ></item>  
  25.     <item text="恢復設置管理" href="DataDictionary/RemoveSchool/RemoveAllSchool.aspx" mce_href="DataDictionary/RemoveSchool/RemoveAllSchool.aspx" roles="超級管理員" ></item>  
  26.   </submenu>  
  27.   
  28.   <submenu id="4" text="考試操作管理">  
  29.     <item text="考試類型管理" href="ExamManagement/ExamType/ExamTypeInformation.aspx" mce_href="ExamManagement/ExamType/ExamTypeInformation.aspx" roles="超級管理員,系統管理員" ></item>  
  30.     <item text="試卷模板管理" href="ExamManagement/ExamTemplate/ExamTemplateInformation.aspx" mce_href="ExamManagement/ExamTemplate/ExamTemplateInformation.aspx" roles="超級管理員,系統管理員" ></item>  
  31.     <item text="試題類型管理" href="ExamManagement/ExaminationType/ExaminationInformation.aspx" mce_href="ExamManagement/ExaminationType/ExaminationInformation.aspx" roles="超級管理員,系統管理員" ></item>  
  32.     <item text="試題題目管理" href="ExamManagement/ExamQuestion/QuestionInformation.aspx" mce_href="ExamManagement/ExamQuestion/QuestionInformation.aspx" roles="超級管理員,系統管理員" ></item>  
  33.     <item text="考試申請管理" href="ExamManagement/ExamApplication/ExamApplicationInformation.aspx" mce_href="ExamManagement/ExamApplication/ExamApplicationInformation.aspx" roles="超級管理員,系統管理員" ></item>  
  34.     <item text="試卷下載管理" href="ExamManagement/ExamDownLoad/ExamDownLoadInformation.aspx" mce_href="ExamManagement/ExamDownLoad/ExamDownLoadInformation.aspx" roles="超級管理員,系統管理員" ></item>  
  35.     <item text="試卷刪除管理" href="ExamManagement/ExamPaperDelete/ExamPaperClear.aspx" mce_href="ExamManagement/ExamPaperDelete/ExamPaperClear.aspx" roles="超級管理員,系統管理員" ></item>  
  36.   </submenu>  
  37.   <submenu id="5" text="報表信息管理">  
  38.     <item text="緩考補考報表" href="ReportInformation/StudentExamState/StudentExamState.aspx" mce_href="ReportInformation/StudentExamState/StudentExamState.aspx" roles="超級管理員,系統管理員,院校長,班主任,教學主管,教學主任,校區考試專員" ></item>  
  39.     <item text="校區考試報表" href="ReportInformation/ExamGrade/ExamGradeReport.aspx" mce_href="ReportInformation/ExamGrade/ExamGradeReport.aspx" roles="超級管理員,系統管理員,院校長,教學主管,教學主任,校區考試專員" ></item>  
  40.     <item text="班級課程報表" href="ReportInformation/StudentExamByClass/StudentExamReport.aspx" mce_href="ReportInformation/StudentExamByClass/StudentExamReport.aspx" roles="超級管理員,系統管理員,院校長,班主任,教學主管,教學主任,校區考試專員" ></item>  
  41.   </submenu>  
  42.   
  43.   <submenu id="6" text="日誌操作管理">  
  44.     <item text="登陸日誌管理" href="LoginManagement/LogLogins.aspx" mce_href="LoginManagement/LogLogins.aspx" roles="超級管理員" ></item>  
  45.     <item text="操作日誌管理" href="LoginManagement/LogOpeations.aspx" mce_href="LoginManagement/LogOpeations.aspx" roles="超級管理員" ></item>  
  46.     <item text="日誌導出" href="LoginManagement/ErportLog.aspx" mce_href="LoginManagement/ErportLog.aspx" roles="超級管理員" >  
  47.     </item>  
  48.   </submenu>  
  49.   
  50.   <submenu id="7" text="個人信息管理">  
  51.     <item text="個人資料修改" href="PersonalManagement/PersonalManagement.aspx" mce_href="PersonalManagement/PersonalManagement.aspx" roles="超級管理員,系統管理員,院校長,班主任,教學主管,教學主任,校區考試專員" ></item>  
  52.   </submenu>  
  53. </menu>  
  

defatult.aspx.cs文件代碼

[c-sharp] view plaincopy
  1. XmlDocument x = new XmlDocument();//實例化一個XML文檔  
  2. protected void Page_Load(object sender, EventArgs e)  
  3. {  
  4.     XMLopertator();  
  5. }  
  6.   
  7. /// <summary>  
  8. /// 循環讀取XML裏的內容  
  9. /// </summary>  
  10. public void XMLopertator()   
  11. {  
  12.     XMLLoad();  
  13.   
  14.     XmlNodeList xnl=x.ChildNodes;   
  15.     foreach (XmlNode xn in xnl)  
  16.     {  
  17.         XmlNodeList xnl1 = xn.ChildNodes;  
  18.         foreach (XmlNode xn1 in xnl1)  
  19.         {  
  20.             XmlNodeList xnl2 = xn1.ChildNodes;  
  21.             foreach (XmlNode xn2 in xnl2)  
  22.             {  
  23.                 Response.Write(xn2.Attributes["text"].Value+"<br/>");  
  24.             }  
  25.         }  
  26.     }  
  27. }  
  28.   
  29. /// <summary>  
  30. /// 加載XML文檔  
  31. /// </summary>  
  32. public void XMLLoad()  
  33. {  
  34.     x.Load(Server.MapPath("~/Left.xml"));  
  35. }  

轉載自:點擊打開鏈接

 

做起來很簡單 的

發佈了28 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章