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); }
public HtmlNodeList QuerySelectAll(QuerySelectorPatterns patts) { HtmlNodeList nodelist = new HtmlNodeList(); QuerySelectAll(this, patts, nodelist); return(nodelist); }
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); }
public HtmlNodeList QuerySelectAll(string pattern) { QuerySelectorPatterns patts = QuerySelectorStringParser.Parse(pattern); if (patts == null) { return(null); } return(QuerySelectAll(patts)); }
public HtmlElement QuerySelector(string pattern) { //TODO: //parse selector pattern QuerySelectorPatterns patts = QuerySelectorStringParser.Parse(pattern); if (patts == null) { return(null); } return(QuerySelector(patts)); }
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); } } }