Beispiel #1
0
        /// <summary>Searches a document for any sub-documents (inside iframes).</summary>
        public static void Search(Document doc, string name, List <DocumentEntry> results)
        {
            if (doc == null)
            {
                return;
            }

            // Add it:
            results.Add(new DocumentEntry(doc, name));

            // Search for iframe's:
            Dom.HTMLCollection set = doc.getElementsByTagName("iframe");

            foreach (Element node in set)
            {
                // Get as a HTML element:
                HtmlElement htmlElement = node as HtmlElement;

                // Double check it's not some evil iframe twin:
                if (htmlElement != null)
                {
                    string src = htmlElement["src"];

                    // Search content doc:
                    Search(htmlElement.contentDocument, src, results);
                }
            }
        }
        /// <summary>Searches a document for any sub-documents (inside iframes).</summary>
        public static Document SearchForID(Document doc, uint id)
        {
            if (doc == null)
            {
                return(null);
            }

            if (doc.uniqueID == id)
            {
                return(doc);
            }

            // Search for iframe's:
            Dom.HTMLCollection set = doc.getElementsByTagName("iframe");

            foreach (Element node in set)
            {
                // Get as a HTML element:
                HtmlElement htmlElement = node as HtmlElement;

                // Double check it's not some evil iframe twin:
                if (htmlElement != null)
                {
                    // Search content doc:
                    Document result = SearchForID(htmlElement.contentDocument, id);

                    if (result != null)
                    {
                        return(result);
                    }
                }
            }

            return(null);
        }
Beispiel #3
0
        /// <summary>Gets the first element which matches the given selector.</summary>
        public Element querySelector(string selector)
        {
            HTMLCollection results = querySelectorAll(selector, true);

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

            return(results[0] as Element);
        }
Beispiel #4
0
        public RadioNodeList(HTMLCollection hc, string name)
        {
            // Find all nodes with the given name/id in the collection:
            foreach (Element e in hc)
            {
                if (e["type"] != "radio")
                {
                    continue;
                }

                if (e["id"] == name || e["name"] == name)
                {
                    values.Add(e);
                }
            }
        }
Beispiel #5
0
        /// <summary>Gets all child elements with the given tag.</summary>
        /// <param name="selector">The selector string to match.</param>
        /// <returns>The set of all tags with this tag.</returns>
        public HTMLCollection querySelectorAll(string selector, bool one)
        {
            // Create results set:
            HTMLCollection results = new HTMLCollection();

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

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

            // Read a value:
            Css.Value value = lexer.ReadValue();

            // Read the selectors from the value:
            List <Selector> selectors = new List <Selector>();

            Css.CssLexer.ReadSelectors(null, value, selectors);

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

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

            // Perform the selection process:
            querySelectorAll(selectors.ToArray(), results, e, false);

            return(results);
        }