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;
}
}
///
/// NodeÌTextÌC³
///
///
///
///
public bool SetNodeText(string xPath,string value)
{
try
{
xd.SelectSingleNode(xPath).InnerText = value;
return true;
}
catch
{
return false;
}
}
///
/// NodeÌTextðæ¾·é
///
///
///
public string GetNodeText(string xPath)
{
return xd.SelectSingleNode(xPath).InnerText;
}
///
/// Nodeõ
///
///
///
public XmlNode? SelectSingleNode(string xPath)
{
return xd.SelectSingleNode(xPath);
}
///
/// Û¶·é
///
///
public bool Save()
{
try
{
xd.Save(fileName);
return true;
}
catch
{
return false;
}
}
#endregion
}
}