예제 #1
0
        /// <summary>
        /// Get inner text by searched attribute node if not null or empty
        /// </summary>
        /// <param name="path">XmlData path</param>
        /// <param name="attributeName">Attribute name to search</param>
        /// <param name="attributeValue">Attribute value to search</param>
        /// <param name="defaultText">Default text if given node is null or empty</param>
        /// <returns></returns>
        public string GetInnerTextByAttributeWithPath(string path, string attributeName, string attributeValue, string defaultText = "")
        {
            if (string.IsNullOrEmpty(path))
            {
                return(null);
            }

            List <string> NAME_LIST = path.Split('/').ToList();

            if (NAME_LIST.Count > 1)
            {
                XmlDataNode foundXmlDataNode = subNodes.Find((XmlDataNode xmlDataNode) =>
                {
                    return(xmlDataNode.name == NAME_LIST[0]);
                });
                if (foundXmlDataNode != null)
                {
                    return(foundXmlDataNode.GetInnerTextByAttributeWithPath(String.Join("/", NAME_LIST.Skip(1)), attributeName, attributeValue, defaultText));
                }
                else
                {
                    return(defaultText);
                }
            }
            else
            {
                XmlDataNode foundXmlDataNode = subNodes.Find((XmlDataNode xmlDataNode) =>
                {
                    return(xmlDataNode.name == NAME_LIST[0] &&
                           xmlDataNode.attribute.ContainsKey(attributeName) &&
                           xmlDataNode.attribute[attributeName] == attributeValue);
                });
                if (foundXmlDataNode != null)
                {
                    return(foundXmlDataNode.innerText);
                }
                else
                {
                    return(defaultText);
                }
            }
        }