Exemple #1
0
        /// <summary>
        /// 得到 XmlNode 的子节点的辅助类.
        /// </summary>
        /// <param name="beginNode">开始的 XmlNode 类.</param>
        /// <param name="xPath">用于搜索的 xpath.</param>
        /// <returns>搜索到子节点辅助类.</returns>
        public static XmlNodeHelper <XmlNode> GetNodeHelper(XmlNode beginNode, string xPath)
        {
            XmlNodeHelper <XmlNode> nodeHelper = null;

            FetchNodeHelper(ref nodeHelper, beginNode, xPath);
            return(nodeHelper);
        }
        /// <summary>
        /// 载入 Xml 文件.
        /// </summary>
        /// <param name="filePath">Xml 文件路径.</param>
        public void Load(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return;
            }

            try
            {
                if (null == this.node)
                {
                    this.node = new XmlDocument( );
                }

                this.node.Load(filePath);
                this.filePath = filePath;
            }
            catch { }

            if (this.node.ChildNodes.Count == 2)
            {
                this.rootNodeHelper = new XmlNodeHelper <XmlNode> (this.node.ChildNodes[1]);
            }

            this.fileNodeHelper = new XmlNodeHelper <XmlNode> (this.node);
        }
Exemple #3
0
        /// <summary>
        /// 得到 XmlNode 的子节点的辅助类.
        /// </summary>
        /// <param name="beginNodeHelper">开始的 XmlNode 辅助类.</param>
        /// <param name="xPath">用于搜索的 xpath.</param>
        /// <returns>搜索到子节点辅助类.</returns>
        public static List <XmlNodeHelper <XmlNode> > GetNodeHelpers(XmlNodeHelper <XmlNode> beginNodeHelper, string xPath)
        {
            if (null == beginNodeHelper)
            {
                return(new List <XmlNodeHelper <XmlNode> > ( ));
            }

            return(GetNodeHelpers(beginNodeHelper.node, xPath));
        }
Exemple #4
0
        /// <summary>
        /// 获取 XmlNode 的子节点的辅助类.
        /// </summary>
        /// <param name="nodeHelper">返回的子节点的辅助类.</param>
        /// <param name="beginNodeHelper">开始的 XmlNode 辅助类.</param>
        /// <param name="xPath">用于搜索的 xpath.</param>
        /// <returns>是否搜索到子节点.</returns>
        public static bool FetchNodeHelper(ref XmlNodeHelper <XmlNode> nodeHelper, XmlNodeHelper <XmlNode> beginNodeHelper, string xPath)
        {
            if (null == beginNodeHelper)
            {
                return(false);
            }

            return(FetchNodeHelper(ref nodeHelper, beginNodeHelper.node, xPath));
        }
Exemple #5
0
        /// <summary>
        /// 获取 XmlNode 的子节点的辅助类.
        /// </summary>
        /// <param name="nodeHelper">返回的子节点的辅助类.</param>
        /// <param name="xPath">用于搜索的 xpath.</param>
        /// <returns>是否搜索到子节点.</returns>
        public bool FetchNodeHelper(ref XmlNodeHelper <XmlNode> nodeHelper, string xPath)
        {
            bool isSuccess = FetchNodeHelper(ref nodeHelper, this.node, xPath);

            this.fetchedNodeHelpers.Clear( );
            this.fetchedNodeHelpers.Add(nodeHelper);

            return(isSuccess);
        }
Exemple #6
0
        /// <summary>
        /// 得到 XmlNode 的子节点的辅助类.
        /// </summary>
        /// <param name="beginNodeHelper">开始的 XmlNode 辅助类.</param>
        /// <param name="xPath">用于搜索的 xpath.</param>
        /// <returns>搜索到子节点辅助类.</returns>
        public static XmlNodeHelper <XmlNode> GetNodeHelper(XmlNodeHelper <XmlNode> beginNodeHelper, string xPath)
        {
            if (null == beginNodeHelper)
            {
                return(null);
            }

            return(GetNodeHelper(beginNodeHelper.node, xPath));
        }
Exemple #7
0
        /// <summary>
        /// 得到辅助类所表示 XmlNode 的属性值.
        /// </summary>
        /// <typeparam name="T">属性的类型.</typeparam>
        /// <param name="nodeHelper">XmlNode 辅助类.</param>
        /// <param name="name">属性名称.</param>
        /// <param name="defaultValue">属性默认值.</param>
        /// <returns>属性值.</returns>
        public static T GetAttributeValue <T> (XmlNodeHelper <XmlNode> nodeHelper, string name, T defaultValue)
#endif
        {
            if (null == nodeHelper)
            {
                return(default(T));
            }

            return(GetAttributeValue <T> (nodeHelper.node, name, defaultValue));
        }
Exemple #8
0
        /// <summary>
        /// 设置辅助类所表示 XmlNode 的属性值.
        /// </summary>
        /// <param name="nodeHelper">XmlNode 辅助类.</param>
        /// <param name="value">属性值.</param>
        /// <param name="name">属性的名称.</param>
        /// <returns>是否成功设置.</returns>
        public static bool FlushAttributeValue(XmlNodeHelper <XmlNode> nodeHelper, object value, string name)
#endif
        {
            if (null == nodeHelper)
            {
                return(false);
            }

            return(FlushAttributeValue(nodeHelper.node, value, name));
        }
Exemple #9
0
        /// <summary>
        /// 获取辅助类所表示 XmlNode 的属性值.
        /// </summary>
        /// <typeparam name="T">属性的类型.</typeparam>
        /// <param name="value">返回的属性值.</param>
        /// <param name="nodeHelper">XmlNode 辅助类.</param>
        /// <param name="name">属性名称.</param>
        /// <param name="defaultValue">属性默认值.</param>
        /// <returns>是否成功获取到 XmlNode 的属性.</returns>
        public static bool FetchAttributeValue <T> (ref T value, XmlNodeHelper <XmlNode> nodeHelper, string name, T defaultValue)
#endif
        {
            if (null == nodeHelper)
            {
                return(false);
            }

            return(FetchAttributeValue <T> (ref value, nodeHelper.node, name, defaultValue));
        }
Exemple #10
0
        /// <summary>
        /// 添加 Xml 节点.
        /// </summary>
        /// <param name="parentNodeHelper">添加到的节点的辅助类.</param>
        /// <param name="childNodeHelper">添加节点的辅助类.</param>
        public static void AppendNode(XmlNodeHelper <XmlNode> parentNodeHelper, XmlNodeHelper <XmlNode> childNodeHelper)
        {
            if (null == parentNodeHelper || null == parentNodeHelper.node || null == childNodeHelper)
            {
                return;
            }

            try
            { parentNodeHelper.node.InnerXml += childNodeHelper.OuterXml; }
            catch { }
        }
        /// <summary>
        /// 在 XmlDocument 中导航到指定的节点.
        /// </summary>
        /// <param name="xPath">导航的路径.</param>
        /// <returns>是否导航成功.</returns>
        public bool Navigate(string xPath)
        {
            if (null == this.currentNodeHelper)
            {
                if (null == this.rootNodeHelper)
                {
                    return(false);
                }

                this.currentNodeHelper = this.rootNodeHelper;
            }

            return(this.currentNodeHelper.FetchNodeHelper(ref this.currentNodeHelper, xPath));
        }
Exemple #12
0
        /// <summary>
        /// 获取 XmlNode 的子节点的辅助类.
        /// </summary>
        /// <param name="nodeHelper">返回的子节点的辅助类.</param>
        /// <param name="beginNode">开始的 XmlNode 类.</param>
        /// <param name="xPath">用于搜索的 xpath.</param>
        /// <returns>是否搜索到子节点.</returns>
        public static bool FetchNodeHelper(ref XmlNodeHelper <XmlNode> nodeHelper, XmlNode beginNode, string xPath)
        {
            List <XmlNodeHelper <XmlNode> > nodeHelpers = GetNodeHelpers(beginNode, xPath);

            if (nodeHelpers.Count == 0)
            {
                return(false);
            }

            nodeHelper = nodeHelpers[0];
            sharedFetchedNodeHelpers.Clear( );
            sharedFetchedNodeHelpers.Add(nodeHelper);
            return(true);
        }
Exemple #13
0
        /// <summary>
        /// 得到辅助类所表示 XmlNode 的属性值.
        /// </summary>
        /// <param name="value">返回的属性值.</param>
        /// <param name="nodeHelper">XmlNode 辅助类.</param>
        /// <param name="name">属性名称.</param>
        /// <param name="defaultValue">属性默认值.</param>
        /// <returns>是否成功获取到 XmlNode 的属性.</returns>
        public static bool FetchAttributeValue(ref object value, XmlNodeHelper <XmlNode> nodeHelper, string name, object defaultValue)
#endif
        {
            return(FetchAttributeValue <object> (ref value, nodeHelper, name, defaultValue));
        }
Exemple #14
0
 /// <summary>
 /// 获取辅助类所表示 XmlNode 的属性值.
 /// </summary>
 /// <typeparam name="T">属性的类型.</typeparam>
 /// <param name="value">返回的属性值.</param>
 /// <param name="nodeHelper">XmlNode 辅助类.</param>
 /// <param name="name">属性名称, 默认为 "value".</param>
 /// <param name="defaultValue">属性默认值, 默认为 default(T).</param>
 /// <returns>是否成功获取到 XmlNode 的属性.</returns>
 public static bool FetchAttributeValue <T> (ref T value, XmlNodeHelper <XmlNode> nodeHelper, string name = null, T defaultValue = default(T))
Exemple #15
0
 /// <summary>
 /// 添加 Xml 节点.
 /// </summary>
 /// <param name="childNodeHelper">添加节点的辅助类.</param>
 public void AppendNode(XmlNodeHelper <XmlNode> childNodeHelper)
 {         /* AppendNode ( this, childNodeHelper ); */
 }
Exemple #16
0
        /// <summary>
        /// 获取 XmlNode 的子节点的辅助类.
        /// </summary>
        /// <param name="beginNode">开始的 XmlNode 类.</param>
        /// <param name="xPath">用于搜索的 xpath.</param>
        /// <returns>是否搜索到子节点.</returns>
        public static bool FetchNodeHelper(XmlNode beginNode, string xPath)
        {
            XmlNodeHelper <XmlNode> nodeHelper = null;

            return(FetchNodeHelper(ref nodeHelper, beginNode, xPath));
        }
Exemple #17
0
 /// <summary>
 /// 得到辅助类所表示 XmlNode 的属性值.
 /// </summary>
 /// <typeparam name="T">属性的类型.</typeparam>
 /// <param name="nodeHelper">XmlNode 辅助类.</param>
 /// <param name="name">属性名称, 默认为 "value".</param>
 /// <param name="defaultValue">属性默认值, 默认为 default(T).</param>
 /// <returns>属性值.</returns>
 public static T GetAttributeValue <T> (XmlNodeHelper <XmlNode> nodeHelper, string name = null, T defaultValue = default(T))
Exemple #18
0
 /// <summary>
 /// 设置辅助类所表示 XmlNode 的属性值.
 /// </summary>
 /// <param name="nodeHelper">XmlNode 辅助类.</param>
 /// <param name="value">属性值.</param>
 /// <param name="name">属性的名称, 默认为 null.</param>
 /// <returns>是否成功设置.</returns>
 public static bool FlushAttributeValue(XmlNodeHelper <XmlNode> nodeHelper, object value, string name = null)
Exemple #19
0
        /// <summary>
        /// 得到辅助类所表示 XmlNode 的属性值.
        /// </summary>
        /// <param name="nodeHelper">XmlNode 辅助类.</param>
        /// <param name="name">属性名称.</param>
        /// <param name="defaultValue">属性默认值.</param>
        /// <returns>属性值.</returns>
        public static object GetAttributeValue(XmlNodeHelper <XmlNode> nodeHelper, string name, object defaultValue)
#endif
        {
            return(GetAttributeValue <object> (nodeHelper, name, defaultValue));
        }
Exemple #20
0
 /// <summary>
 /// 得到辅助类所表示 XmlNode 的属性值.
 /// </summary>
 /// <param name="nodeHelper">XmlNode 辅助类.</param>
 /// <param name="name">属性名称, 默认为 "value".</param>
 /// <param name="defaultValue">属性默认值, 默认为 null.</param>
 /// <returns>属性值.</returns>
 public static object GetAttributeValue(XmlNodeHelper <XmlNode> nodeHelper, string name = null, object defaultValue = null)
 /// <summary>
 /// 重新设置当前节点的位置.
 /// </summary>
 public void Reset( )
 {
     this.currentNodeHelper = null;
 }
Exemple #22
0
 /// <summary>
 /// 得到辅助类所表示 XmlNode 的属性值.
 /// </summary>
 /// <param name="value">返回的属性值.</param>
 /// <param name="nodeHelper">XmlNode 辅助类.</param>
 /// <param name="name">属性名称, 默认为 "value".</param>
 /// <param name="defaultValue">属性默认值, 默认为 null.</param>
 /// <returns>是否成功获取到 XmlNode 的属性.</returns>
 public static bool FetchAttributeValue(ref object value, XmlNodeHelper <XmlNode> nodeHelper, string name = null, object defaultValue = null)