本文整理汇总了C#中Attributes.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Attributes.Put方法的具体用法?C# Attributes.Put怎么用?C# Attributes.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attributes
的用法示例。
在下文中一共展示了Attributes.Put方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
internal override bool Process(Token t, HtmlTreeBuilder tb)
{
switch (t.type)
{
case TokenType.Character:
{
Token.Character c = t.AsCharacter();
if (c.GetData().Equals(HtmlTreeBuilderState.nullString))
{
// todo confirm that check
tb.Error(this);
return false;
}
else if (tb.FramesetOk() && HtmlTreeBuilderState.IsWhitespace(c))
{
// don't check if whitespace if frames already closed
tb.ReconstructFormattingElements();
tb.Insert(c);
}
else
{
tb.ReconstructFormattingElements();
tb.Insert(c);
tb.FramesetOk(false);
}
break;
}
case TokenType.Comment:
{
tb.Insert(t.AsComment());
break;
}
case TokenType.Doctype:
{
tb.Error(this);
return false;
}
case TokenType.StartTag:
{
Token.StartTag startTag = t.AsStartTag();
string name = startTag.Name();
if (name.Equals("html"))
{
tb.Error(this);
// merge attributes onto real html
Element html = tb.GetStack().First.Value;
foreach (Supremes.Nodes.Attribute attribute in startTag.GetAttributes())
{
if (!html.HasAttr(attribute.Key))
{
html.Attributes.Put(attribute);
}
}
}
else if (StringUtil.In(name, HtmlTreeBuilderState.Constants.InBodyStartToHead))
{
return tb.Process(t, HtmlTreeBuilderState.InHead);
}
else if (name.Equals("body"))
{
tb.Error(this);
IList<Element> stack = tb.GetStack();
if (stack.Count == 1 || (stack.Count > 2 && !stack[1].NodeName.Equals("body")))
{
// only in fragment case
return false;
}
else
{
// ignore
tb.FramesetOk(false);
Element body = stack[1];
foreach (Supremes.Nodes.Attribute attribute in startTag.GetAttributes())
{
if (!body.HasAttr(attribute.Key))
{
body.Attributes.Put(attribute);
}
}
}
}
else if (name.Equals("frameset"))
{
tb.Error(this);
var stack = tb.GetStack();
if (stack.Count == 1 || (stack.Count > 2 && !stack[1].NodeName.Equals("body")))
{
// only in fragment case
return false;
// ignore
}
else if (!tb.FramesetOk())
{
return false;
// ignore frameset
}
else
//.........这里部分代码省略.........
示例2: CreateSafeElement
private Cleaner.ElementMeta CreateSafeElement(Element sourceEl)
{
string sourceTag = sourceEl.TagName;
Attributes destAttrs = new Attributes();
Element dest = new Element(Tag.ValueOf(sourceTag), sourceEl.BaseUri, destAttrs);
int numDiscarded = 0;
Attributes sourceAttrs = sourceEl.Attributes;
foreach (Attribute sourceAttr in sourceAttrs)
{
if (whitelist.IsSafeAttribute(sourceTag, sourceEl, sourceAttr))
{
destAttrs.Put(sourceAttr);
}
else
{
numDiscarded++;
}
}
Attributes enforcedAttrs = whitelist.GetEnforcedAttributes(sourceTag);
destAttrs.SetAll(enforcedAttrs);
return new Cleaner.ElementMeta(dest, numDiscarded);
}