コード例 #1
0
        public static bool IsSameDomElement(Element one, Element two)
        {
            if (one.tagName != two.tagName)
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(one.namespaceURI) || !string.IsNullOrEmpty(two.namespaceURI))
            {
                if (one.namespaceURI != two.namespaceURI)
                {
                    return(false);
                }
            }

            //For these purposes, the attributes must be compared as they were when the elements were created by the parser; two elements have the same attributes if all their parsed attributes can be paired such that the two attributes in each pair have identical names, namespaces, and values (the order of the attributes does not matter).

            if (one.attributes.Count() != two.attributes.Count())
            {
                return(false);
            }

            foreach (var item in one.attributes)
            {
                string valueInTwo = two.getAttribute(item.name);

                if (valueInTwo != item.value)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #2
0
ファイル: Element.cs プロジェクト: yhforever4/Kooboo
        private Element _getElementById(Node topElement, string id)
        {
            if (topElement.nodeType == enumNodeType.ELEMENT)
            {
                Element element = (Element)topElement;

                if (element.hasAttribute("id"))
                {
                    string idvalue = element.getAttribute("id");
                    if (idvalue == id)
                    {
                        return(element);
                    }
                }
            }

            foreach (var item in topElement.childNodes.item)
            {
                Element returnelement = _getElementById(item, id);
                if (returnelement != null)
                {
                    return(returnelement);
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: InlineAnalyzer.cs プロジェクト: xhute/Kooboo
        private Dictionary <string, string> ReplaceInlineCssUrl(Kooboo.Dom.Element element, AnalyzerContext Context)
        {
            string csstext = element.getAttribute("style");

            if (string.IsNullOrEmpty(csstext))
            {
                return(null);
            }

            Dictionary <string, string> replace = new Dictionary <string, string>();

            var urlInfos = Service.CssService.GetUrlInfos(csstext);

            foreach (var item in urlInfos)
            {
                if (string.IsNullOrEmpty(item.PureUrl) || item.PureUrl.Trim().ToLower().StartsWith("#"))
                {
                    continue;
                }

                string newurl = string.Empty;
                if (item.isImportRule)
                {
                    newurl = CssManager.AddImport(item.PureUrl, Context.AbsoluteUrl, Context.DownloadManager, Context.ObjectId);
                }
                else
                {
                    if (Kooboo.Lib.Utilities.DataUriService.isDataUri(item.PureUrl))
                    {
                        newurl = CssManager.ParseDataUri(item.PureUrl, Context.DownloadManager);
                    }
                    else
                    {
                        newurl = CssManager.DownloadCssFile(item.PureUrl, Context.AbsoluteUrl, Context.DownloadManager, Context.ObjectId);
                    }
                }

                if (newurl != item.PureUrl)
                {
                    replace.Add(item.PureUrl, newurl);
                }
            }

            return(replace);
        }
コード例 #4
0
ファイル: Element.cs プロジェクト: yhforever4/Kooboo
        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);
            }
        }
コード例 #5
0
ファイル: Element.cs プロジェクト: yhforever4/Kooboo
        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);
            }
        }