Beispiel #1
0
        /// <summary>Selects elements from this document using the given CSS selector.
        /// Do note that this is not designed to be used in high-performance situations and
        /// you should cache the results as much as possible.</summary>
        public Dom.NodeList querySelectorAll(string selector, bool one)
        {
            // Create results set:
            Dom.NodeList results = new Dom.NodeList();

            if (string.IsNullOrEmpty(selector))
            {
                // Empty set:
                return(results);
            }

            Node root = documentElement;

            // Create the lexer:
            Css.CssLexer lexer = new Css.CssLexer(selector, root);

            List <Css.Selector> all = new List <Css.Selector>();

            // Read selectors:
            lexer.ReadSelectors(all);

            if (all.Count == 0)
            {
                // Invalid selector:
                return(results);
            }

            // Create a blank event to store the targets, if any:
            CssEvent e = new CssEvent();

            // Perform the selection process:
            (root as IRenderableNode).querySelectorAll(all.ToArray(), results, e, one);

            return(results);
        }
Beispiel #2
0
        /// <summary>Selects the first element from this document that matches the given CSS selector.
        /// Do note that this is not designed to be used in high-performance situations and
        /// you should cache the results as much as possible.</summary>
        public Element querySelector(string selector)
        {
            Dom.NodeList results = querySelectorAll(selector, true);

            if (results == null || results.length == 0)
            {
                return(null);
            }

            return(results[0] as Element);
        }