コード例 #1
0
        /// <summary>
        /// Gets the node with xml path.
        /// </summary>
        /// <example>xxx.NodePath("A.B.C") or xxx.NodePath("A.B.C.D[E]")</example>
        /// <param name="xmlPath">The XML path.</param>
        /// <returns>FluentXml instance.</returns>
        public FluentXml NodePath(string xmlPath)
        {
            if (this.IsNullOrWhiteSpace(xmlPath))
            {
                return(this);
            }

            if (!xmlPath.Contains("."))
            {
                return(this.GetNodeWithIndex(xmlPath));
            }
            else
            {
                var propertyChain = xmlPath.Trim().Split('.');

                FluentXml result = this;

                foreach (var propertyName in propertyChain)
                {
                    if (!propertyName.EndsWith("]"))
                    {
                        result = result.Node(propertyName);
                    }
                    else
                    {
                        return(result.GetNodeWithIndex(propertyName));
                    }
                }

                return(result);
            }
        }