• 读取XML文件内容


    创建XML文件

     1 <?xml version="1.0" encoding="utf-8" ?>
     2 <Custom>
     3   <CaseType ID="1" Parent="0" Title="刑事案件">
     4     <CountA ID ="10" Parent="1" Title="小计"></CountA>
     5     <YiShen ID="11" Parent="1" Title="一审"></YiShen>
     6     <ErShenFH ID="12" Parent="1" Title="二审复核">
     7       <ErShen ID="121" Parent="12" Title="二审">
     8         <ShangSu ID="1211" Parent="121" Title="上诉"></ShangSu>
     9         <KangSu ID="1212" Parent="121" Title="抗诉">
    10           <SiXing ID="12121" Parent="1212" Title="死刑"></SiXing>
    11           <NoSiXing ID="12122" Parent="1212" Title="非死刑">
    12             <WuZui ID="121221" Parent="12122" Title="无罪"></WuZui>
    13             <YouZui ID="121222" Parent="12122" Title="有罪"></YouZui>
    14           </NoSiXing>
    15         </KangSu>
    16       </ErShen>
    17       <FuHe ID ="122" Parent="12" Title="复核"></FuHe>
    18     </ErShenFH>
    19     <ZaiShen ID="13" Parent="1" Title="再审">
    20       <KangSuAgain ID="131" Parent="13" Title="抗诉再审"></KangSuAgain>
    21       <ZhiLingAgain ID="132" Parent="13" Title="指令再审"></ZhiLingAgain>
    22       <TiqiAgain ID="133" Parent="13" Title="本院提起再审"></TiqiAgain>
    23     </ZaiShen>
    24     <ShenSu ID="14" Parent="1" Title="申诉复查"></ShenSu>
    25     <FaDingXing ID="15" Parent="1" Title="法定刑以下核准"></FaDingXing>
    26     <QingShi ID="16" Parent="1" Title="请示">
    27       <GeAn ID="161" Parent="16" Title="个案请示">
    28         <FaLv ID="1611" Parent="161" Title="法律问题请示"></FaLv>
    29         <YiGuiDing ID="1612" Parent="161" Title="依规定内审"></YiGuiDing>
    30       </GeAn>
    31       <LeiAn ID="162" Parent="16" Title="类案请示"></LeiAn>
    32       <OtherCase ID="163" Parent="16" Title="其他案件"></OtherCase>
    33     </QingShi>
    34     <ZhongJie ID="17" Parent="1" Title="终结"></ZhongJie>
    35     <QiTa ID="18" Parent="1" Title="其他"></QiTa>
    36   </CaseType>
    37 
    38   <CaseType ID="2" Parent="0" Title="民事案件">
    39     <CountB ID ="20" Parent="2" Title="小计"></CountB>
    40     <YiShen ID="21" Parent="2" Title="一审"></YiShen>
    41     <ErShen ID="22" Parent="2" Title="二审"></ErShen>
    42     <ShenCha ID ="23" Parent="2" Title="再审审查"></ShenCha>
    43     <ZaiShen ID="24" Parent="2" Title="再审">
    44       <KangSuAgain ID="241" Parent="24" Title="抗诉再审"></KangSuAgain>
    45       <ZhiLingAgain ID="242" Parent="24" Title="指令再审"></ZhiLingAgain>
    46       <TiqiAgain ID="243" Parent="24" Title="本院提起再审"></TiqiAgain>
    47     </ZaiShen>
    48     <ShenSu ID="25" Parent="2" Title="申诉复查"></ShenSu>
    49     <QingShi ID="26" Parent="2" Title="请示">
    50       <GeAn ID="261" Parent="26" Title="个案请示">
    51         <FaLv ID="2611" Parent="261" Title="法律问题请示"></FaLv>
    52         <YiGuiDing ID="2612" Parent="261" Title="依规定内审"></YiGuiDing>
    53       </GeAn>
    54       <LeiAn ID="262" Parent="26" Title="类案请示"></LeiAn>
    55       <OtherCase ID="263" Parent="26" Title="其他案件"></OtherCase>
    56     </QingShi>
    57     <ZhongJie ID="27" Parent="2" Title="终结"></ZhongJie>
    58     <QiTa ID="28" Parent="2" Title="其他"></QiTa>
    59   </CaseType>
    60 
    61   <CaseType ID="3" Parent="0" Title="行政案件">
    62     <CountC ID ="30" Parent="3" Title="小计"></CountC>
    63     <YiShen ID="31" Parent="3" Title="一审"></YiShen>
    64     <ErShen ID="32" Parent="3" Title="二审"></ErShen>
    65     <ShenCha ID ="33" Parent="3" Title="再审审查"></ShenCha>
    66     <ZaiShen ID="34" Parent="3" Title="再审">
    67       <KangSuAgain ID="341" Parent="34" Title="抗诉再审"></KangSuAgain>
    68       <ZhiLingAgain ID="342" Parent="34" Title="指令再审"></ZhiLingAgain>
    69       <TiqiAgain ID="343" Parent="34" Title="本院提起再审"></TiqiAgain>
    70     </ZaiShen>
    71     <ShenSu ID="35" Parent="3" Title="申诉复查"></ShenSu>
    72     <Guojia ID="36" Parent="3" Title="国家赔偿"></Guojia>
    73     <QiTa ID="37" Parent="3" Title="其他"></QiTa>
    74   </CaseType>
    75 </Custom>
    创建XML文件

    读取XML文件内容

     1  /// <summary>
     2         /// 读取XML文件内容
     3         /// </summary>
     4         /// <returns></returns>
     5         public static List<CustomReport> CustomReport()
     6         {
     7             List<CustomReport> obj = new List<Model.CustomReport>();
     8             string filePath = HttpRuntime.AppDomainAppPath + @"XMLCustomReport.xml";
     9             XmlDocument xmlDoc = new XmlDocument();
    10             xmlDoc.Load(filePath);
    11             XmlNode caseTypes1 = xmlDoc.SelectSingleNode("Custom");
    12             XmlNodeList caseTypes = caseTypes1.ChildNodes;
    13 
    14             foreach (XmlNode item in caseTypes)
    15             {
    16                 CustomReport re = new CustomReport();
    17                 //    //案件类型
    18                 re.ID = item.Attributes["ID"].Value;
    19                 re.Parent = item.Attributes["Parent"].Value;
    20                 re.Title = item.Attributes["Title"].Value;
    21                 obj.Add(re);
    22                 //如果存在子节点
    23                 if (item.HasChildNodes)
    24                 {
    25                     foreach (XmlNode secondTd in item.ChildNodes)
    26                     {
    27                         CustomReport sec = new CustomReport();
    28                         //第二层标题
    29                         sec.ID = secondTd.Attributes["ID"].Value;
    30                         sec.Parent = secondTd.Attributes["Parent"].Value;
    31                         sec.Title = secondTd.Attributes["Title"].Value;
    32                         obj.Add(sec);
    33 
    34                         if (secondTd.HasChildNodes)
    35                         {
    36                             foreach (XmlNode thirdTd in secondTd.ChildNodes)
    37                             {
    38                                 CustomReport thi = new CustomReport();
    39                                 //第三层标题
    40                                 thi.ID = thirdTd.Attributes["ID"].Value;
    41                                 thi.Parent = thirdTd.Attributes["Parent"].Value;
    42                                 thi.Title = thirdTd.Attributes["Title"].Value;
    43                                 obj.Add(thi);
    44                                 if (thirdTd.HasChildNodes)
    45                                 {
    46                                     foreach (XmlNode fourthTd in thirdTd.ChildNodes)
    47                                     {
    48                                         CustomReport fou = new CustomReport();
    49                                         //第四层标题
    50                                         fou.ID = fourthTd.Attributes["ID"].Value;
    51                                         fou.Parent = fourthTd.Attributes["Parent"].Value;
    52                                         fou.Title = fourthTd.Attributes["Title"].Value;
    53                                         obj.Add(fou);
    54 
    55                                         if (fourthTd.HasChildNodes)
    56                                         {
    57                                             foreach (XmlNode fifthTd in fourthTd.ChildNodes)
    58                                             {
    59                                                 CustomReport fif = new CustomReport();
    60                                                 //第五层标题
    61                                                 fif.ID = fifthTd.Attributes["ID"].Value;
    62                                                 fif.Parent = fifthTd.Attributes["Parent"].Value;
    63                                                 fif.Title = fifthTd.Attributes["Title"].Value;
    64                                                 obj.Add(fif);
    65 
    66                                                 if (fifthTd.HasChildNodes)
    67                                                 {
    68                                                     foreach (XmlNode sixthTd in fifthTd.ChildNodes)
    69                                                     {
    70                                                         CustomReport six = new CustomReport();
    71                                                         //第六层标题
    72                                                         six.ID = sixthTd.Attributes["ID"].Value;
    73                                                         six.Parent = sixthTd.Attributes["Parent"].Value;
    74                                                         six.Title = sixthTd.Attributes["Title"].Value;
    75                                                         obj.Add(six);
    76 
    77                                                     }
    78                                                 }
    79                                             }
    80                                         }
    81                                     }
    82                                 }
    83                             }
    84                         }
    85                     }
    86                 }
    87             }
    88             return obj;
    89         }
    读取XML文件内容

    生成并赋值表格内容

     1  /// <summary>
     2         /// 加载自定义表
     3         /// </summary>
     4         /// <param name="Year"></param>
     5         /// <param name="Month"></param>
     6         /// <param name="caseStatus"></param>
     7         /// <returns></returns>
     8         public string CustomReport(string Year, string Month, string caseStatus)
     9         {
    10             string color = "";
    11             string color_xingshi = "background-color: #bfbfbf";//刑事
    12             string color_minshi = "background-color:#b8cce4";//民事
    13             string color_xingzheng = "background-color: #e6b9b8";//行政
    14             string color_department = "background-color:#79ff79";//部门
    15             string color_sum = "background-color:#ffe66f";//小计
    16             string width = "30";
    17             string nowrap_department = "white-space:nowrap";//部门列表禁止换行
    18             string align = "text-align: center";
    19             string verTical = "vertical-align: top";
    20             int colspan = 4;
    21             int rowspan = 4;
    22             int year = ParamPlus.GetIntParamValue("Year");
    23             int month = ParamPlus.GetIntParamValue("Month");
    24             if (year <= 0 || month <= 0)
    25             {
    26                 year = DateTime.Now.Year;
    27                 month = DateTime.Now.Month;
    28             }
    29             string casetype = ParamPlus.GetStringParamValue("caseStatus");
    30             DateTime date = DateTime.Parse(year + "-" + month + "-01");
    31             // 请求数据
    32             DateTime startTime = date.AddDays(1 - date.Day);  //月初
    33             DateTime endTime = startTime.AddMonths(1).AddDays(-1);  //月末
    34             string trStart = "<tr>";
    35             string trEnd = "</tr>";
    36             //部门列表
    37             StringBuilder tableDepartment = new StringBuilder();
    38             StringBuilder departmentList = new StringBuilder();
    39             //第一层标题
    40             StringBuilder tableHead = new StringBuilder();
    41             //第二层标题
    42             StringBuilder SecondtableHead = new StringBuilder();
    43             //第三层标题
    44             StringBuilder ThirdtableHead = new StringBuilder();
    45             //第四层标题
    46             StringBuilder FourthtableHead = new StringBuilder();
    47             //第五层标题
    48             StringBuilder FifthtableHead = new StringBuilder();
    49             //第六层标题
    50             StringBuilder SixthtableHead = new StringBuilder();
    51             //合计
    52             StringBuilder Sum = new StringBuilder();
    53             //加载部门
    54             tableDepartment.AppendFormat("<th style="{0};{1}" width="100" nowrap align="center" rowspan="7">{2}</th>", color_department, nowrap_department, "部门");
    55 
    56             #region 第一层标题
    57             //第一层标题
    58             foreach (var item in listall)
    59             {
    60                 if (caseStatus.Contains("刑事") && item.ID == "1" && item.Parent == "0")//刑事
    61                 {
    62                     width = "auto";
    63                     colspan = 18;
    64                     tableHead.AppendFormat("<th style="{0};{1};{2}" width="{3}" colspan="{4}">{5}</th>", color_xingshi, align, verTical, width, colspan, item.Title);
    65                 }
    66                 else if (caseStatus.Contains("民事") && item.ID == "2" && item.Parent == "0")//民事
    67                 {
    68                     width = "auto";
    69                     colspan = 14;
    70                     tableHead.AppendFormat("<th style="{0};{1};{2}" width="{3}" colspan="{4}">{5}</th>", color_minshi, align, verTical, width, colspan, item.Title);
    71                 }
    72                 else if (caseStatus.Contains("行政") && item.ID == "3" && item.Parent == "0")//行政
    73                 {
    74                     width = "auto";
    75                     colspan = 10;
    76                     tableHead.AppendFormat("<th style="{0};{1};{2}" width="{3}" colspan="{4}">{5}</th>", color_xingzheng, align, verTical, width, colspan, item.Title);
    77                 }
    78             }
    79             .............
    80  StringBuilder thead = new StringBuilder();
    81             thead.AppendFormat(trStart + tableDepartment + trEnd);//部门
    82             thead.AppendFormat(trStart + tableHead + trEnd);//第一层
    83             thead.AppendFormat(trStart + SecondtableHead + trEnd);//第二层
    84             thead.AppendFormat(trStart + ThirdtableHead + trEnd);//第三层
    85             thead.AppendFormat(trStart + FourthtableHead + trEnd);//第四层
    86             thead.AppendFormat(trStart + FifthtableHead + trEnd);//第五层
    87             thead.AppendFormat(trStart + SixthtableHead + trEnd);//第六层
    88             thead.AppendFormat(trStart + departmentList + trEnd);//部门列表
    89             thead.AppendFormat(trStart + Sum + trEnd);//合计
    90             return thead.ToString();
    91         }             
    生成并赋值表格

    解析xml内容:

    var doc = new XmlDocument();
    doc.LoadXml(xml);
    var node = doc.SelectSingleNode("Topics");
    if (node != null)
    {
       if (node.HasChildNodes)
       {
          model.ID = node.SelectNodes("TopicsId").Item(0).InnerText;
       }
    }
  • 相关阅读:
    华为OJ平台——DNA序列
    华为OJ平台——整数的二进制中1的个数
    华为OJ平台——首次不重复字符
    Unity-iPhone has Conflicting Provisioning Settings
    升级MAC OS到10.13, 10.14系统后UNITY工程无法加载资源的解决办法
    Unity各平台内置宏定义
    Xcode官方xip直接离线下载地址(更新到Xcode 9.4.1)
    Machine Learning In Action
    Unity3D Errors And Fix
    Crash for small compressed texture on some Android device
  • 原文地址:https://www.cnblogs.com/lijianda/p/6640856.html
Copyright © 2020-2023  润新知