using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace COMM
{
public class XMLClass
{
XmlDocument Xmldoc;
public void LoadXMLFile(string xml)
{
try
{
Xmldoc = new XmlDocument();
Xmldoc.Load(xml);
}
catch (Exception ex)
{
throw ex;
}
}
public void LoadXML(string xml)
{
try
{
Xmldoc = new XmlDocument();
Xmldoc.LoadXml(xml);
}
catch (Exception ex)
{
throw ex;
}
}
public void Destroy()
{
Xmldoc = null;
}
public void CreateNode(string NodePath, string NodeName, string Value)
{
try
{
XmlNode Node, NewNode;
Node = Xmldoc.SelectSingleNode(NodePath);
NewNode = Xmldoc.CreateNode(XmlNodeType.Element, NodeName, "");
NewNode.InnerText = Value;
Node.AppendChild(NewNode);
}
catch (Exception ex)
{
throw ex;
}
}
public void CreateNode(string NodePath, string NodeName)
{
try
{
XmlNode Node, NewNode;
Node = Xmldoc.SelectSingleNode(NodePath);
NewNode = Xmldoc.CreateNode(XmlNodeType.Element, NodeName, "");
Node.AppendChild(NewNode);
}
catch (Exception ex)
{
throw ex;
}
}
public void ResetNodeValue(string NodePath, string Value)
{
try
{
XmlNode Node;
Node = Xmldoc.SelectSingleNode(NodePath);
Node.InnerText = Value;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// xmlDocument.SelectSingleNode("config/application/Title").InnerText;
/// </summary>
/// <param name="NodePath"></param>
/// <returns></returns>
public string GetNodeValue(string NodePath)
{
try
{
return Xmldoc.SelectSingleNode(NodePath).InnerText;
}
catch (Exception ex)
{
throw ex;
}
}
public void DelNode(string ParentNodePath,string NodePath)
{
try
{
XmlNode DelNode =Xmldoc.SelectSingleNode(NodePath);
XmlNode ParentNode = Xmldoc.SelectSingleNode(ParentNodePath);
ParentNode.RemoveChild(DelNode);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// xmlDocument.GetElementsByTagName("_95105951");
/// </summary>
/// <param name="ElementsByTagName"></param>
/// <returns></returns>
public XmlNodeList GetNodeList(string ElementsByTagName)
{
try
{
return Xmldoc.GetElementsByTagName(ElementsByTagName);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// <Queue Name="业务程序收送数据的对队"> <IP SendAddress="192.168.100.1" RequestAddress="192.168.100.1"/> <port sendPort="8083" requestPort="8082"/> <queueNo sendLine="1018" requestLine="1018"/> <MMS SendAddress="192.168.100.1" sendPort="8083"/> </Queue>
/// </summary>
/// <param name="NodeName"></param>
/// <param name="AttributeName"></param>
public string GetAttribute(XmlNodeList NodeList,string NodeName, string AttributeName)
{
try
{
if (NodeList == null)
{
return "空";
}
foreach (XmlNode node in NodeList)
{
return node[NodeName].GetAttribute(AttributeName).ToString();
}
return "空";
}
catch (Exception ex)
{
throw ex;
}
}
public string GetAttribute(string NodeListName, string NodeName, string AttributeName)
{
try
{
XmlNodeList NodeList = Xmldoc.GetElementsByTagName(NodeListName);
foreach (XmlNode node in NodeList)
{
string str = node[NodeName].GetAttribute(AttributeName).ToString();
return str;
}
return "空";
}
catch (Exception ex)
{
throw ex;
}
}
public SortedList<string, string> GetAttribute(string NodeListName, string NodeName, string AttributeName1,string AttributeName2)
{
try
{
SortedList<string, string> sList = new SortedList<string, string>();
XmlNodeList NodeList = Xmldoc.GetElementsByTagName(NodeListName);
foreach (XmlNode node in NodeList)
{
sList.Add(node[NodeName].GetAttribute(AttributeName1).ToString(), node[NodeName].GetAttribute(AttributeName2).ToString());
}
return sList;
}
catch (Exception ex)
{
throw ex;
}
}
public string GetXml()
{
return Xmldoc.OuterXml;
}
}
}
/*<?xml version="1.0" encoding="GB2312"?>
<!-- edited with XMLSpy v2005 rel. 3 U (http://www.altova.com) by () -->
<config>
<!--应用程序配置-->
<application>
<!--程序名称-->
<Title>西岸网讯Keygoe驱动程序</Title>
<!--SocketClient类重新连接资源的周期以毫秒为单位-->
<SocketClientInterVal>5000</SocketClientInterVal>
<!--事件显示在程序界面的时间-->
<DisInterVal>1000000</DisInterVal>
<!--程序判断SocketClient类的状态时间-->
<SocketInterVal>1000</SocketInterVal>
<!--程序判断SocketClient类断开次数后重起-->
<SocketCount>30</SocketCount>
<!--激活包发送时间-->
<HeartInterVal>5000</HeartInterVal>
<!--会议检查时间-->
<ConfInterVal>600000</ConfInterVal>
<!--资源层的IP-->
<ServerIPAddress>192.168.100.176</ServerIPAddress>
<!--资源层的端口-->
<ServerPort>8888</ServerPort>
<!--本程序运行的IP-->
<IPAddress>192.168.100.204</IPAddress>
<!--录音文件位置-->
<RecordPath>E:/shar/vox/</RecordPath>
</application>
<keygoe>
<ServerIPAddress>192.168.100.176</ServerIPAddress>
<ServerPort>9000</ServerPort>
<UserName/>
<PassWord/>
<DspWorkID>,1,2,</DspWorkID>
<u8AppID>1</u8AppID>
</keygoe>
<CTIPhone>
<_951>
<_95105951>
<DspID ID="1" E1="0"/>
</_95105951>
</_951>
<_1258>
<_12581258>
<DspID ID="1" E1="1"/>
</_12581258>
<_12581258>
<DspID ID="2" E1="0,3"/>
</_12581258>
<_12581258>
<DspID ID="0" E1="0"/>
</_12581258>
</_1258>
<_400>
<_4008899400>
<DspID ID="0" E1="0"/>
</_4008899400>
<_4008899400>
<DspID ID="0" E1="0"/>
</_4008899400>
</_400>
<_Seat>
<_SeatID>
<DspID ID="1" E1="2"/>
</_SeatID>
</_Seat>
<_1258In>
<_12581258In>
<DspID ID="1" E1="1"/>
</_12581258In>
</_1258In>
</CTIPhone>
<datapack><![CDATA[<?xml version="1.0"?><pack><head><ver>2000</ver><oper>%s</oper><gid>%s</gid><stream>%s</stream><from>%s</from><to>%s</to></head><body/></pack>]]></datapack>
</config>
*/