CaseQuery() public static method

Returns the query as either a case sensitive or case insensitive query.
public static CaseQuery ( string queryPart, bool ignoreCase ) : string
queryPart string /// The part of the query to process. ///
ignoreCase bool /// if set to true the query will ignore case. ///
return string
Esempio n. 1
0
        private static string BuildTagExpression(SupportedTagAttribute supportedTag)
        {
            // HTML tag names are case folded to lower case
            var queryTagName = supportedTag.TagName.ToLowerInvariant();

            if (supportedTag.HasAttributeFilter)
            {
                const string AttributeFilterQuery = "*[local-name() = '{0}' and {1}='{2}']";

                // HTML attribute names are case folded to lower case
                // Searching by the SupportedTagAttribute attribute value must be case insensitive
                var attributeName      = supportedTag.AttributeName.ToLowerInvariant();
                var queryAttributeName = QueryFactory.CaseQuery("@" + attributeName, true);

                // This literal value can be converted to lower case here rather than within the execution of the XPath query
                var queryAttributeValue = supportedTag.AttributeValue.ToLowerInvariant();

                return(string.Format(
                           CultureInfo.CurrentCulture,
                           AttributeFilterQuery,
                           queryTagName,
                           queryAttributeName,
                           queryAttributeValue));
            }

            return("*[local-name() = '" + queryTagName + "']");
        }
        public IEnumerable <T> AllByText(string text, bool ignoreCase)
        {
            if (text == null)
            {
                text = string.Empty;
            }

            var    tagSelector = BuildElementQuery();
            string textFilter;

            if (ignoreCase)
            {
                // The text value is a literal value in the query
                // so it can be converted to lower case here rather than within the execution of the XPath query
                textFilter = "[" + QueryFactory.CaseQuery("./text()", true) + " = '" + text.ToLowerInvariant() + "']";
            }
            else
            {
                textFilter = "[./text() = '" + text + "']";
            }

            var query = tagSelector + textFilter;

            return(Execute(query));
        }