示例#1
0
        internal StyleSheetList(CssXmlDocument document)
        {
            _cssXmlDoc = document;
            XmlNodeList pis = document.SelectNodes("/processing-instruction()");

            _styleSheets = new List <StyleSheet>();

            foreach (XmlProcessingInstruction pi in pis)
            {
                if (Regex.IsMatch(pi.Data, "type=[\"']text\\/css[\"']"))
                {
                    _styleSheets.Add(new CssStyleSheet(pi, CssStyleSheetType.Author));
                }
                else
                {
                    _styleSheets.Add(new StyleSheet(pi));
                }
            }

            XmlNodeList styleNodes;

            foreach (string[] name in document._styleElements)
            {
                //TODO: Fixed style finding - yavor87 committed on Sep 17, 2016
                //styleNodes = document.SelectNodes("//*[local-name()='" + name[1]
                //    + "' and namespace-uri()='" + name[0] + "'][@type='text/css' or not(@type)]");

                styleNodes = document.SelectNodes(
                    "//*[local-name()='" + name[1] + "' and namespace-uri()='" + name[0] + "']");

                if (styleNodes == null)
                {
                    continue;
                }

                foreach (XmlElement elm in styleNodes)
                {
                    var styleType = elm.GetAttribute("type");

                    // Check for valid 'type' attribute of the style element
                    if (string.IsNullOrWhiteSpace(styleType) ||
                        string.Equals(styleType, "text/css", StringComparison.OrdinalIgnoreCase))
                    {
                        _styleSheets.Add(new CssStyleSheet(elm, CssStyleSheetType.Author));
                    }
                }
            }
        }