zoukankan      html  css  js  c++  java
  • Xml 文件读取

    .NET 读取Xml文件,用到XmlDocument类。

    1、要获取文档的根: DocumentElement

    2、Attributes :获取 XmlAttributeCollection 包含此节点的属性。 (主体操作都是获取属性值)

     1  DirectoryInfo dir = new DirectoryInfo(@"D:XXXXML"); //文件夹路径
     2             FileInfo[] fileInfo = dir.GetFiles();
     3             Dictionary<string, List<string>> tabDic = new Dictionary<string, List<string>>();
     4             foreach (FileInfo item in fileInfo)
     5             {
     6                 string path = item.DirectoryName + "\" + item.Name;
     7                 XmlDocument doc = new XmlDocument();
     8                 doc.Load(path);
     9                 XmlNode root = doc.DocumentElement; //根节点
    10                 XmlNodeList nodes = root.SelectNodes("ormTable");
    11                 foreach (XmlNode node in nodes)
    12                 {
    13                     string tableName = node.Attributes["tableName"].Value;  //获取表名
    14                     List<string> lstField = new List<string>();     //文件字段长度>0的字段列表
    15                     XmlNodeList fieldsNode = node.SelectNodes("Field"); //各个字段
    16                     foreach (XmlNode fnode in fieldsNode)
    17                     {
    18                         //文件字段长度大于0,加入列表
    19                         if (fnode.Attributes["filePath"].Value.Length > 0)
    20                         {
    21                             lstField.Add(fnode.Attributes["fieldName"].Value);
    22                         }
    23                     }
    24                     if (lstField.Count > 0)
    25                     {
    26                         //表名不在字典中
    27                         if (!tabDic.ContainsKey(tableName))
    28                         {
    29                             tabDic.Add(tableName, lstField);
    30                         }
    31                     }
    32                 }
    33             }
    读取文件夹中所有Xml文件
  • 相关阅读:
    POJ3122贪心或者二分(分蛋糕)
    POJ2118基础矩阵快速幂
    POJ2118基础矩阵快速幂
    POJ1328贪心放雷达
    POJ1328贪心放雷达
    hdu4642博弈(矩阵)
    hdu4642博弈(矩阵)
    POJ1042 贪心钓鱼
    POJ3160强连通+spfa最长路(不错)
    POJ3114强连通+spfa
  • 原文地址:https://www.cnblogs.com/meng9527/p/9083331.html
Copyright © 2011-2022 走看看