qwj
2022-08-22 63f6c5de8832eaabf066fe9f9d492187f04011b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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);
        }
        /// <summary>
        /// 给定一个节点的xPath表达式并返回一个节点
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public XmlNode FindNode(string xPath)
        {
            XmlNode xmlNode = this.SelectSingleNode(xPath);
            return xmlNode;
        }
        /// <summary>
        /// 给定一个节点的xPath表达式返回其值
        /// </summary>
        /// <param name="xPath"></param>
        /// <returns></returns>
        public string GetNodeValue(string xPath)
        {
            XmlNode xmlNode = this.SelectSingleNode(xPath);//5~1-a-s-p-x
            return xmlNode.InnerText;
        }
 
        /// <summary>
        /// 修改节点值
        /// </summary>
        /// <param name="xPath"></param>
        /// <param name="xValue"></param>
        public void UpdateNodeValue(string xPath,string xValue)
        {
            XmlNode xmlNode = this.SelectSingleNode(xPath);
            xmlNode.InnerText = xValue;
            this.Save(XmlFileName);
        }
        /// <summary>
        /// 给定一个节点的表达式返回此节点下的孩子节点列表
        /// </summary>
        /// <param name="xPath"></param>
        /// <returns></returns>
        public XmlNodeList GetNodeList(string xPath)
        {
            XmlNodeList nodeList = this.SelectSingleNode(xPath).ChildNodes;
            return nodeList;
 
        }
 
    }
}