using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace CY_DocumentSynchroWCFService
{
public class XmlFiles : XmlDocument
{
#region 字段与属性
private string _xmlFileName;
public string XmlFileName
{
set { _xmlFileName = value; }
get { return _xmlFileName; }
}
#endregion
public XmlFiles(string xmlFile)
{
XmlFileName = xmlFile;
this.Load(xmlFile);
}
///
/// 给定一个节点的xPath表达式并返回一个节点
///
///
///
public XmlNode FindNode(string xPath)
{
XmlNode xmlNode = this.SelectSingleNode(xPath);
return xmlNode;
}
///
/// 给定一个节点的xPath表达式返回其值
///
///
///
public string GetNodeValue(string xPath)
{
XmlNode xmlNode = this.SelectSingleNode(xPath);//5~1-a-s-p-x
return xmlNode.InnerText;
}
///
/// 修改节点值
///
///
///
public void UpdateNodeValue(string xPath,string xValue)
{
XmlNode xmlNode = this.SelectSingleNode(xPath);
xmlNode.InnerText = xValue;
this.Save(XmlFileName);
}
///
/// 给定一个节点的表达式返回此节点下的孩子节点列表
///
///
///
public XmlNodeList GetNodeList(string xPath)
{
XmlNodeList nodeList = this.SelectSingleNode(xPath).ChildNodes;
return nodeList;
}
}
}