using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using System.Xml;
|
|
namespace HotelPms.Share.Xml
|
{
|
public class XmlOperation
|
{
|
/// ****************************** Description *******************************
|
/// VXe¼Ì
|
/// @ÄpNX
|
/// Tv
|
/// @XMLÌìFÇÁAC³AíAõÈÇ
|
/// <>gpû@
|
/// ð
|
/// @2007/11/10 ¬Ø@´ VKì¬
|
/// ****************************** Declarations ******************************
|
#region @Declartions@
|
|
private string fileName;
|
private XmlDocument? xd;
|
|
#endregion
|
|
#region @Property@
|
|
public string FileName
|
{
|
get { return fileName; }
|
set { fileName = value; }
|
}
|
|
#endregion
|
|
#region @Class Event@
|
|
public XmlOperation()
|
: this("")
|
{
|
}
|
|
public XmlOperation(string fileName)
|
{
|
if (!fileName.Equals(""))
|
{
|
this.fileName = fileName;
|
}
|
xd = new XmlDocument();
|
xd.Load(this.fileName);
|
}
|
|
#endregion
|
|
#region @Private Function@
|
#endregion
|
|
#region @Public Function@
|
|
public XmlElement? AddNode(string parentXPath, string key, string value)
|
{
|
try
|
{
|
XmlElement ownerNode = (XmlElement)xd.SelectSingleNode(parentXPath);
|
XmlElement newNode = xd.CreateElement(key);
|
newNode.InnerText = value;
|
ownerNode.AppendChild(newNode);
|
return newNode;
|
}
|
catch
|
{
|
return null;
|
}
|
}
|
|
/// <summary>
|
/// NodeÌTextÌC³
|
/// </summary>
|
/// <param name="xPath"></param>
|
/// <param name="value"></param>
|
/// <returns></returns>
|
public bool SetNodeText(string xPath,string value)
|
{
|
try
|
{
|
xd.SelectSingleNode(xPath).InnerText = value;
|
return true;
|
}
|
catch
|
{
|
return false;
|
}
|
}
|
|
/// <summary>
|
/// NodeÌTextðæ¾·é
|
/// </summary>
|
/// <param name="xPath"></param>
|
/// <returns></returns>
|
public string GetNodeText(string xPath)
|
{
|
return xd.SelectSingleNode(xPath).InnerText;
|
}
|
|
|
/// <summary>
|
/// Nodeõ
|
/// </summary>
|
/// <param name="xPath"></param>
|
/// <returns></returns>
|
public XmlNode? SelectSingleNode(string xPath)
|
{
|
return xd.SelectSingleNode(xPath);
|
}
|
|
/// <summary>
|
/// Û¶·é
|
/// </summary>
|
/// <returns></returns>
|
public bool Save()
|
{
|
try
|
{
|
xd.Save(fileName);
|
return true;
|
}
|
catch
|
{
|
return false;
|
}
|
}
|
|
#endregion
|
}
|
}
|