protected void Create(string selector, CQ context) { // when creating a new CsQuery from another, leave Dom blank - it will be populated automatically with the // contents of the selector. CsQueryParent = context; if (!String.IsNullOrEmpty(selector)) { Selectors = new SelectorChain(selector); AddSelectionRange(Selectors.Select(Document, context.Children())); } }
//<summary> // Filter an element list using another selector. A null selector results in no filtering. //</summary> //<param name="?"></param> //<param name="selector"></param> protected IEnumerable <IDomObject> filterElementsIgnoreNull(IEnumerable <IDomObject> elements, string selector) { if (selector == "") { return(Objects.EmptyEnumerable <IDomObject>()); } else if (selector == null) { return(elements); } else { SelectorChain selectors = new SelectorChain(selector); if (selectors.Count > 0) { selectors.Do(item => item.TraversalType = TraversalType.Filter); } // this is kind of unfortunate but is required to keep the order correct. Probably a more efficient // way to do it but works fine for now return(elements.Intersect(selectors.Select(Document, elements))); } }
//<summary> // Filter an element list using another selector. A null selector results in no filtering. //</summary> //<param name="?"></param> //<param name="selector"></param> protected IEnumerable<IDomObject> filterElementsIgnoreNull(IEnumerable<IDomObject> elements, string selector) { if (selector=="") { return Objects.EmptyEnumerable<IDomObject>(); } else if (selector == null) { return elements; } else { SelectorChain selectors = new SelectorChain(selector); if (selectors.Count > 0) { selectors.ForEach(item=>item.TraversalType = TraversalType.Filter); } // this is kind of unfortunate but is required to keep the order correct. Probably a more efficient // way to do it but works fine for now return elements.Intersect(selectors.Select(Document, elements)); } }
public IList <IDomElement> QuerySelectorAll(string selector) { SelectorChain selectors = new SelectorChain(selector); return((new List <IDomElement>(OnlyElements(selectors.Select(Document)))).AsReadOnly()); }
public IList <IDomElement> GetElementsByTagName(string tagName) { SelectorChain selectors = new SelectorChain(tagName); return((new List <IDomElement>(OnlyElements(selectors.Select(Document)))).AsReadOnly()); }
public IDomElement GetElementById(string id) { SelectorChain selectors = new SelectorChain("#" + id); return((IDomElement)selectors.Select(Document).FirstOrDefault()); }