#region 简要描述
/*=============================================================================
* 文件 :ReadXML.cs
* 包 :DPT.DEWMS.Common.Reports
* 类 :ReadXML
* 描述 :读取xml配置文件节点。
*
* 作者 :徐晓清
* 创建日期:2009年01月7日
* 备注 :
============================================================================*/
#endregion
using System;
using System.Xml;
using System.Collections;
using System.Windows.Forms;
using System.Data;
namespace DPT.DEWMS.Common.Reports
{
/// <summary>
/// ReadXML 的摘要说明。
/// </summary>
public class ReadXML
{
private string xmlPath;//ReportSetting.xml文件所在路径
private XmlTextReader xmlReader;
private Hashtable hashNodes;
public Hashtable HashNodes
{
get
{
return hashNodes;
}
}
public ReadXML()
{
//
// TODO: 在此处添加构造函数逻辑
//
string curpath = Application.StartupPath;
xmlPath = curpath +"//"+"ReportSetting.xml";
}
public void ReadNodes(string reportID)
{
#region 读xml文件
hashNodes = null;
string tempID = null;
try
{
xmlReader = new XmlTextReader(xmlPath);
while(xmlReader.Read())
{
switch(xmlReader.NodeType)
{
case XmlNodeType.Element:
{
if(string.Compare(xmlReader.Name.ToUpper(),"REPORT",true)==0)
{
tempID = xmlReader["ID"];
if(tempID == reportID)
{
hashNodes = new Hashtable();
}
}
if(string.Compare(xmlReader.Name.ToUpper(),"TEMPLATE",true)==0)
{
if(tempID == reportID)
{
if(xmlReader.HasAttributes)
{
XmlProperties xmlPro = new XmlProperties();
xmlPro.Name = xmlReader["Name"];
xmlPro.FileName = xmlReader["FileName"];
hashNodes.Add(xmlPro.Name,xmlPro);
}
}
}
break;
}
default:
break;
}
}
}
catch( Exception ex)
{
MessageBox.Show(ex.Message);
}
#endregion
}
}
#region ReportSetting.xml文件的节点属性
/// <summary>
/// 目前只读取了name和filename
/// </summary>
class XmlProperties
{
string name;
string fileName;
public XmlProperties()
{
}
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public string FileName
{
get
{
return fileName;
}
set
{
fileName = value;
}
}
#endregion
}
}