Exemple #1
0
 public HtmlElement QuerySelector(QuerySelectorPatterns patts)
 {
     //eval child node
     if (ChildrenCount < 1)
     {
         return(null);
     }
     //----------
     foreach (DomNode childnode in this.GetChildNodeIterForward())
     {
         if (childnode.NodeKind == HtmlNodeKind.OpenElement)
         {
             HtmlElement htmlElem = (HtmlElement)childnode;
             if (!patts.Evaluate((HtmlElement)childnode))
             {
                 //not found
                 HtmlElement found = ((HtmlElement)childnode).QuerySelector(patts);
                 if (found != null)
                 {
                     return(found);
                 }
             }
             else
             {
                 //found
                 return((HtmlElement)childnode);
             }
         }
     }
     return(null);
 }
Exemple #2
0
        public HtmlNodeList QuerySelectAll(QuerySelectorPatterns patts)
        {
            HtmlNodeList nodelist = new HtmlNodeList();

            QuerySelectAll(this, patts, nodelist);
            return(nodelist);
        }
Exemple #3
0
        public static QuerySelectorPatterns Parse(string querySelectorStr)
        {
            QuerySelectorPatterns querySelectorPattern = new QuerySelectorPatterns();


            //https://developer.mozilla.org/en-US/docs/Web/API/Document_object_model/Locating_DOM_elements_using_selectors
            //Selectors

            //The selector methods accept one or more comma-separated selectors to determine what element or
            //elements should be returned. For example, to select all paragraph(p) elements in
            //a document whose CSS class is either warning or note, you can do the following:

            //var special = document.querySelectorAll("p.warning, p.note");
            //        You can also query by ID.For example:
            //        var el = document.querySelector("#main, #basic, #exclamation");
            //        After executing the above code, el contains the first element in the document whose ID is one of main, basic, or exclamation.
            //        You may use any CSS selectors with the querySelector() and querySelectorAll() methods.

            //TODO: review here again
            string[] patts = querySelectorStr.Split(seps, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < patts.Length; ++i)
            {
                //parse each pattern
                QuerySelectorPattern patt = ParsePattern(patts[i].Trim());
                if (patt != null)
                {
                    querySelectorPattern.AddPattern(patt);
                }
            }
            return(querySelectorPattern);
        }
Exemple #4
0
        public HtmlNodeList QuerySelectAll(string pattern)
        {
            QuerySelectorPatterns patts = QuerySelectorStringParser.Parse(pattern);

            if (patts == null)
            {
                return(null);
            }
            return(QuerySelectAll(patts));
        }
Exemple #5
0
        public HtmlElement QuerySelector(string pattern)
        {
            //TODO:
            //parse selector pattern
            QuerySelectorPatterns patts = QuerySelectorStringParser.Parse(pattern);

            if (patts == null)
            {
                return(null);
            }
            return(QuerySelector(patts));
        }
Exemple #6
0
 static void QuerySelectAll(HtmlElement elem, QuerySelectorPatterns patts, HtmlNodeList nodelist)
 {
     if (elem.ChildrenCount < 1)
     {
         return;
     }
     //----------
     foreach (DomNode childnode in elem.GetChildNodeIterForward())
     {
         if (childnode.NodeKind == HtmlNodeKind.OpenElement)
         {
             HtmlElement htmlElem = (HtmlElement)childnode;
             if (patts.Evaluate((HtmlElement)childnode))
             {
                 //found
                 nodelist.AddSelectedItem(htmlElem);
             }
             QuerySelectAll(htmlElem, patts, nodelist);
         }
     }
 }