当前位置: 首页>>代码示例>>C#>>正文


C# IHtmlElement.GetAttribute方法代码示例

本文整理汇总了C#中IHtmlElement.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# IHtmlElement.GetAttribute方法的具体用法?C# IHtmlElement.GetAttribute怎么用?C# IHtmlElement.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHtmlElement的用法示例。


在下文中一共展示了IHtmlElement.GetAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Check

 public override IHtmlElement Check(IHtmlElement elem,IHtmlElement root = null)
 {
     var attr = elem.GetAttribute(this.AttributeName);
     if (attr == null) return null;
     if (this.AttributeValue != null) {
         return this.AttributeValue == attr?elem:null;
     }
     return elem;
 }
开发者ID:yanyitec,项目名称:Yanyitec,代码行数:9,代码来源:AttributeFilter.cs

示例2: ConvertAnchorElement

 private static TextElement ConvertAnchorElement(IHtmlElement anchorHtmlElement)
 {
     IEnumerable<Inline> hyperlinkContent = anchorHtmlElement.ChildNodes.Select(child => HtmlConverter.ConvertHtmlNode(child)).OfType<Inline>();
     Hyperlink hyperlink = new Hyperlink();
     hyperlink.Inlines.AddRange(hyperlinkContent);
     string hyperReference = anchorHtmlElement.GetAttribute("href");
     Uri navigationUri;
     if (Uri.TryCreate(hyperReference, UriKind.RelativeOrAbsolute, out navigationUri))
         hyperlink.NavigateUri = navigationUri;
     return hyperlink;
 }
开发者ID:lecode-official,项目名称:xaml-reporting,代码行数:11,代码来源:HtmlConverter.cs

示例3: SanitizeStyle

        /// <summary>
        /// Sanitizes the style.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="baseUrl">The base URL.</param>
        protected void SanitizeStyle(IHtmlElement element, string baseUrl)
        {
            // filter out invalid CSS declarations
            // see https://github.com/FlorianRappl/AngleSharp/issues/101
            if (element.GetAttribute("style") == null) return;
            element.SetAttribute("style", element.Style.ToCss());

            var styles = element.Style;
            if (styles == null || styles.Length == 0) return;

            var removeStyles = new List<Tuple<ICssProperty, RemoveReason>>();
            var setStyles = new Dictionary<string, string>();

            foreach (var style in styles)
            {
                var key = DecodeCss(style.Name);
                var val = DecodeCss(style.Value);

                if (!AllowedCssProperties.Contains(key))
                {
                    removeStyles.Add(new Tuple<ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedStyle));
                    continue;
                }

                if(CssExpression.IsMatch(val) || DisallowCssPropertyValue.IsMatch(val))
                {
                    removeStyles.Add(new Tuple<ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedValue));
                    continue;
                }

                var urls = CssUrl.Matches(val);

                if (urls.Count > 0)
                {
                    if (urls.Cast<Match>().Any(m => GetSafeUri(m.Groups[2].Value) == null || SanitizeUrl(m.Groups[2].Value, baseUrl) == null))
                        removeStyles.Add(new Tuple<ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedUrlValue));
                    else
                    {
                        var s = CssUrl.Replace(val, m => "url(" + m.Groups[1].Value + SanitizeUrl(m.Groups[2].Value, baseUrl) + m.Groups[3].Value);
                        if (s != val)
                        {
                            if (key != style.Name)
                            {
                                removeStyles.Add(new Tuple<ICssProperty, RemoveReason>(style, RemoveReason.NotAllowedUrlValue));
                            }
                            setStyles[key] = s;
                        }
                    }
                }
            }

            foreach (var style in removeStyles)
            {
                RemoveStyle(element, styles, style.Item1, style.Item2);
            }

            foreach (var style in setStyles)
            {
                styles.SetProperty(style.Key, style.Value);
            }
        }
开发者ID:304NotModified,项目名称:HtmlSanitizer,代码行数:66,代码来源:HtmlSanitizer.cs

示例4: HasSummaryCellAttributes

 private static bool HasSummaryCellAttributes(IHtmlElement cell)
 {
     return cell.GetAttribute("COLSPAN") == "3";
 }
开发者ID:mhenry07,项目名称:ASPUnitRunner,代码行数:4,代码来源:ResultParser.cs


注:本文中的IHtmlElement.GetAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。