예제 #1
0
        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()));
            }
        }
예제 #2
0
        //<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)));
            }
        }
예제 #3
0
        //<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));
            }
        }
        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()));
            }
        }
예제 #5
0
        public IList <IDomElement> QuerySelectorAll(string selector)
        {
            SelectorChain selectors = new SelectorChain(selector);

            return((new List <IDomElement>(OnlyElements(selectors.Select(Document)))).AsReadOnly());
        }
예제 #6
0
        public IList <IDomElement> GetElementsByTagName(string tagName)
        {
            SelectorChain selectors = new SelectorChain(tagName);

            return((new List <IDomElement>(OnlyElements(selectors.Select(Document)))).AsReadOnly());
        }
예제 #7
0
        public IDomElement GetElementById(string id)
        {
            SelectorChain selectors = new SelectorChain("#" + id);

            return((IDomElement)selectors.Select(Document).FirstOrDefault());
        }