C# 读XML文件

/// <summary>
/// xml文件路径+名称
/// </summary>
public void ReadXml(string xmlname)
{

  try
  {
    XmlDataDocument doc = new XmlDataDocument();
    doc.Load(xmlname);

    XmlNode dataTableSettingsNode = doc.SelectSingleNode("DataTable_Settings");//根结点
    XmlNode dataCellsNode = dataTableSettingsNode.SelectSingleNode("data_cells");
    if (null == dataCellsNode) return;
    XmlNodeList dataCellNode = dataCellsNode.SelectNodes("data_cell");
    List<SelectColumn> selectColumns = new List<SelectColumn>();
    foreach (XmlNode node in dataCellNode)
    {
      SelectColumn selectColumn = new SelectColumn();
      selectColumn.ColumnName = node.SelectSingleNode("cell_name").InnerText;
      selectColumn.ChineseColumnName = node.SelectSingleNode("chinese_name").InnerText;
      selectColumn.IsVisible = bool.Parse(node.SelectSingleNode("visible").InnerText);
      selectColumn.Width = int.Parse(node.SelectSingleNode("width").InnerText);
      selectColumn.ShowIndex = int.Parse(node.SelectSingleNode("align").InnerText);
      selectColumns.Add(selectColumn);
    }
  }
catch (Exception ex)
{

}
}

上一篇:50种不同编程语言的“Hello, World”,你会写几种?


下一篇:百度架构师是怎样搭建MySQL分布式集群?