Пример #1
0
 public void Merge(HTMLCollection collection)
 {
     foreach (var anotheritem in collection.item)
     {
         item.Add(anotheritem);
     }
 }
Пример #2
0
        public HTMLCollection getElementsByAttribute(string AttributeName)
        {
            HTMLCollection collection = new HTMLCollection();

            _getElementByAttribute(this, collection, AttributeName.ToLower());
            return(collection);
        }
Пример #3
0
        private HTMLCollection getElementByCSSSelector(List <simpleSelector> selectorList)
        {
            HTMLCollection collection = new HTMLCollection();

            _getElementByCSSSelector(this, collection, selectorList);

            return(collection);
        }
Пример #4
0
        /// <summary>
        /// get Elements by class name. Class name is case sensitive.
        /// </summary>
        /// <param name="classNames"></param>
        /// <returns></returns>
        public HTMLCollection getElementsByClassName(string classNames)
        {
            HTMLCollection collection = new HTMLCollection();

            _getElementByClassName(this, collection, classNames);

            return(collection);
        }
Пример #5
0
        public HTMLCollection getElementsByAttributeValues(string AttributeName, string AttributeValue)
        {
            if (string.IsNullOrEmpty(AttributeValue))
            {
                return(getElementsByAttribute(AttributeName));
            }

            HTMLCollection collection = new HTMLCollection();

            _getElementByAttributeValue(this, collection, AttributeName.ToLower(), AttributeValue.ToLower());
            return(collection);
        }
Пример #6
0
        public HTMLCollection getElementsByTagNames(params string[] tagNames)
        {
            for (int i = 0; i < tagNames.Length; i++)
            {
                tagNames[i] = tagNames[i].Trim().ToLower();
            }

            HTMLCollection collection = new HTMLCollection();

            _getElementByTagNames(this, collection, tagNames);

            return(collection);
        }
Пример #7
0
        public HTMLCollection getElementsByTagName(string tagName)
        {
            if (tagName.Contains(","))
            {
                return(getElementsByTagNames(tagName.Split(',')));
            }
            else
            {
                HTMLCollection collection = new HTMLCollection();

                _getElementByTagName(this, collection, tagName.Trim().ToLower());
                return(collection);
            }
        }
Пример #8
0
        private void _getElementByCSSSelector(Node topElement, HTMLCollection collection, List <simpleSelector> selectorList)
        {
            if (topElement.nodeType == enumNodeType.ELEMENT)
            {
                Element element = (Element)topElement;
                if (selectorMatch.Match(element, selectorList))
                {
                    collection.Add(element);
                }
            }

            foreach (var item in topElement.childNodes.item)
            {
                _getElementByCSSSelector(item, collection, selectorList);
            }
        }
Пример #9
0
        private void _getElementByAttribute(Node topElement, HTMLCollection collection, string AttributeName)
        {
            if (topElement.nodeType == enumNodeType.ELEMENT)
            {
                Element element = (Element)topElement;
                if (element.hasAttribute(AttributeName))
                {
                    collection.Add(element);
                }
            }

            foreach (var item in topElement.childNodes.item)
            {
                _getElementByAttribute(item, collection, AttributeName);
            }
        }
Пример #10
0
        private void _getElementByTagNames(Node topElement, HTMLCollection collection, params string[] tagnames)
        {
            if (topElement.nodeType == enumNodeType.ELEMENT)
            {
                Element element = (Element)topElement;
                if (element.tagName.isOneOf(tagnames))
                {
                    collection.Add(element);
                }
            }

            foreach (var item in topElement.childNodes.item)
            {
                _getElementByTagNames(item, collection, tagnames);
            }
        }
Пример #11
0
        private void _getElementByTagName(Node topElement, HTMLCollection collection, string tagname)
        {
            if (topElement.nodeType == enumNodeType.ELEMENT)
            {
                Element element = (Element)topElement;
                if (tagname.Equals("*") || element.tagName == tagname)
                {
                    collection.Add(element);
                }
            }

            foreach (var item in topElement.childNodes.item)
            {
                _getElementByTagName(item, collection, tagname);
            }
        }
Пример #12
0
        private void _getElementByAttributeValue(Node topElement, HTMLCollection collection, string AttributeName, string AttributeValue)
        {
            if (topElement.nodeType == enumNodeType.ELEMENT)
            {
                Element element = (Element)topElement;

                string value = element.getAttribute(AttributeName);

                if (!string.IsNullOrEmpty(value) && value.ToLower() == AttributeValue)
                {
                    collection.Add(element);
                }
            }

            foreach (var item in topElement.childNodes.item)
            {
                _getElementByAttributeValue(item, collection, AttributeName, AttributeValue);
            }
        }
Пример #13
0
        private void _getElementByClassName(Node topElement, HTMLCollection collection, string classnames)
        {
            if (topElement.nodeType == enumNodeType.ELEMENT)
            {
                Element element = (Element)topElement;

                if (element.hasAttribute("class"))
                {
                    string classvalue = element.getAttribute("class");

                    if (!string.IsNullOrEmpty(classvalue))
                    {
                        string[] classlist = classnames.Split(' ');

                        bool matched = true;

                        foreach (var item in classlist)
                        {
                            if (!classvalue.Contains(item))
                            {
                                matched = false;
                                break;
                            }
                        }

                        if (matched)
                        {
                            collection.Add(element);
                        }
                    }
                }
            }

            foreach (var item in topElement.childNodes.item)
            {
                _getElementByClassName(item, collection, classnames);
            }
        }
Пример #14
0
        /// <summary>
        /// parse and download the stylesheets and make them available at StyleSheets.
        /// </summary>
        public void ParseStyleSheet()
        {
            HTMLCollection styletags = this.getElementsByTagName("link, style");

            HTMLCollection availablesheets = new HTMLCollection();

            foreach (var item in styletags.item)
            {
                if (item.tagName == "style")
                {
                    availablesheets.Add(item);
                }

                else if (item.hasAttribute("type"))
                {
                    if (item.getAttribute("type").ToLower().Contains("css"))
                    {
                        availablesheets.Add(item);
                    }
                }
                else if (item.hasAttribute("rel"))
                {
                    if (item.getAttribute("rel").ToLower().Contains("stylesheet"))
                    {
                        availablesheets.Add(item);
                    }
                }
            }

            foreach (var item in availablesheets.item)
            {
                if (item.tagName == "link")
                {
                    string href = item.getAttribute("href");

                    if (string.IsNullOrEmpty(href))
                    {
                        continue;
                    }

                    string absoluteUrl = PathHelper.combine(this.getBaseUrl(), href);

                    string cssText = Loader.LoadCss(absoluteUrl);

                    if (string.IsNullOrEmpty(cssText))
                    {
                        continue;
                    }

                    CSSStyleSheet newStyleSheet = CSSParser.ParseCSSStyleSheet(cssText, absoluteUrl, true);
                    newStyleSheet.ownerNode = item;

                    if (newStyleSheet != null)
                    {
                        newStyleSheet.ownerNode = item;

                        string media = item.getAttribute("media");
                        if (!string.IsNullOrEmpty(media))
                        {
                            string[] medialist = media.Split(',');
                            foreach (var mediaitem in medialist)
                            {
                                newStyleSheet.Medialist.appendMedium(mediaitem);
                            }
                        }
                        this.StyleSheets.appendStyleSheet(newStyleSheet);
                    }
                }

                else if (item.tagName == "style")
                {
                    string cssText = item.InnerHtml;

                    CSSStyleSheet newStyleSheet = CSSParser.ParseCSSStyleSheet(cssText, this.getBaseUrl(), true);

                    newStyleSheet.ownerNode = item;

                    string media = item.getAttribute("media");
                    if (!string.IsNullOrEmpty(media))
                    {
                        string[] medialist = media.Split(',');
                        foreach (var mediaitem in medialist)
                        {
                            newStyleSheet.Medialist.appendMedium(mediaitem);
                        }
                    }
                    this.StyleSheets.appendStyleSheet(newStyleSheet);
                }
            }

            hasParseCSS = true;
        }
Пример #15
0
        public Element getElementsById(string id)
        {
            HTMLCollection collection = new HTMLCollection();

            return(_getElementById(this, id));
        }