本文整理汇总了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;
}
示例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;
}
示例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);
}
}
示例4: HasSummaryCellAttributes
private static bool HasSummaryCellAttributes(IHtmlElement cell)
{
return cell.GetAttribute("COLSPAN") == "3";
}