xmlparser.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace cdqy.kup
{
/// <summary>
/// XML解析
/// </summary>
public class Parser
{
/// <summary>
/// 读取XML字段
/// </summary>
/// <param name="strTree"></param>
/// <param name="rank"></param>
/// <param name="strAttribute"></param>
/// <returns></returns>
public static XmlNode readNode(string strSection, string strRank)
{
string strConfig = Utils.ReadFile(Utils.MapPath("/app.xml"));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strConfig);
XmlNodeList xnl = xmlDoc.GetElementsByTagName(strSection);
if (!String.IsNullOrEmpty(strRank))
{
return xnl[Convert.ToInt32(strRank)];
}
else
{
return xnl[0];
}
}
public static XmlNode readNode(XmlNode node, string strSeciton, string strRank)
{
if (node != null)
{
foreach (XmlNode s in node.ChildNodes)
{
if (s.Name == strSeciton)
{
return s;
}
}
return null;
}
else
{
return readNode(strSeciton, strRank);
}
}
public static XmlNode getNode(string[] strSection, string[] strRank)
{
XmlNode tempXn = null;
for (int i = 0; i < strSection.Length; i++)
{
if (i == 0)
{
tempXn = readNode(null, strSection[i], strRank[i]);
}
else
{
tempXn = readNode(tempXn, strSection[i], strRank[i]);
}
}
return tempXn;
}
public static XmlNode getNode(string[] strSection)
{
XmlNode tempXn = null;
for (int i = 0; i < strSection.Length; i++)
{
if (i == 0)
{
tempXn = readNode(null, strSection[i], "0");
}
else
{
tempXn = readNode(tempXn, strSection[i], "0");
}
}
return tempXn;
}
}
}
浙公网安备 33010602011771号