本文整理汇总了C#中HtmlAgilityPack.HtmlAttribute类的典型用法代码示例。如果您正苦于以下问题:C# HtmlAttribute类的具体用法?C# HtmlAttribute怎么用?C# HtmlAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HtmlAttribute类属于HtmlAgilityPack命名空间,在下文中一共展示了HtmlAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clone
/// <summary>
/// Creates a duplicate of this attribute.
/// </summary>
/// <returns>The cloned attribute.</returns>
public HtmlAttribute Clone()
{
HtmlAttribute att = new HtmlAttribute(_ownerdocument);
att.Name = Name;
att.Value = Value;
return att;
}
示例2: HtmlAttributeWrapper
public HtmlAttributeWrapper(HtmlAttribute wrappedAttribute)
{
if(wrappedAttribute == null)
throw new ArgumentNullException("wrappedAttribute");
_wrappedAttribute = wrappedAttribute;
}
示例3: MakeAbsolute
private static void MakeAbsolute(HtmlAttribute attr, Uri baseUrl) {
var url = attr.Value;
if (!url.StartsWith("http:", StringComparison.OrdinalIgnoreCase)
&& !url.StartsWith("https:", StringComparison.OrdinalIgnoreCase)
&& Uri.IsWellFormedUriString(url, UriKind.Relative)) {
attr.Value = new Uri(baseUrl, url).ToString();
}
}
示例4: ExtractModel
private string ExtractModel(string make, HtmlAttribute htmlAttribute)
{
if (htmlAttribute != null)
{
var stringToReplace = string.Format(@"/usedcar/{0}__", make);
return htmlAttribute.Value.Replace(stringToReplace, string.Empty).Replace(".html", string.Empty);
}
return string.Empty;
}
示例5: Prepend
/// <summary>
/// Inserts the specified attribute as the first node in the collection.
/// </summary>
/// <param name="newAttribute">The attribute to insert. May not be null.</param>
/// <returns>The prepended attribute.</returns>
public HtmlAttribute Prepend(HtmlAttribute newAttribute)
{
if (newAttribute == null)
{
throw new ArgumentNullException("newAttribute");
}
_hashitems[newAttribute.Name] = newAttribute;
newAttribute._ownernode = _ownernode;
_items.Insert(0, newAttribute);
_ownernode._innerchanged = true;
_ownernode._outerchanged = true;
return newAttribute;
}
示例6: RetrieveImageUrl
private string RetrieveImageUrl(HtmlAttribute htmlAttribute)
{
try
{
var url = htmlAttribute.Value;
var htmlDocument = _htmlWeb.Load(url);
if (htmlDocument.DocumentNode != null)
{
var node = htmlDocument.DocumentNode.SelectSingleNode("//*[@id = 'frontCover']");
if (node != null)
{
return string.Format("{0}{1}", BaseUrl, node.Attributes["src"].Value);
}
}
return null;
}
catch (Exception)
{
return null;
}
}
示例7: HtmlAttributeAdapter
internal HtmlAttributeAdapter( AP.HtmlAttribute attribute )
{
_attribute = attribute;
}
示例8: Remove
/// <summary>
/// Removes a given attribute from the list.
/// </summary>
/// <param name="attribute">The attribute to remove. May not be null.</param>
public void Remove(HtmlAttribute attribute)
{
if (attribute == null)
{
throw new ArgumentNullException("attribute");
}
int index = GetAttributeIndex(attribute);
if (index == -1)
{
throw new IndexOutOfRangeException();
}
RemoveAt(index);
}
示例9: GetAttributeIndex
internal int GetAttributeIndex(HtmlAttribute attribute)
{
if (attribute == null)
{
throw new ArgumentNullException("attribute");
}
for (int i = 0; i < _items.Count; i++)
{
if (((HtmlAttribute)_items[i]) == attribute)
return i;
}
return -1;
}
示例10: CleanAttributeValues
/// <summary>
/// This removes the vulnerable keywords and make values safe by html encoding and html character escaping.
/// </summary>
/// <param name="attribute">Attribute that contain values that need to check and clean.</param>
private void CleanAttributeValues(HapHtmlAttribute attribute)
{
if (CleanAttributes)
{
attribute.Value = HttpUtility.HtmlEncode(attribute.Value);
attribute.Value = Regex.Replace(attribute.Value, @"\s*j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*", "", RegexOptions.IgnoreCase);
attribute.Value = Regex.Replace(attribute.Value, @"\s*s\s*c\s*r\s*i\s*p\s*t\s*", "", RegexOptions.IgnoreCase);
if (attribute.Name.ToLower() == "style")
{
attribute.Value = Regex.Replace(attribute.Value, @"\s*e\s*x\s*p\s*r\s*e\s*s\s*s\s*i\s*o\s*n\s*", "", RegexOptions.IgnoreCase);
attribute.Value = Regex.Replace(attribute.Value, @"\s*b\s*e\s*h\s*a\s*v\s*i\s*o\s*r\s*", "", RegexOptions.IgnoreCase);
}
if (attribute.Name.ToLower() == "href" || attribute.Name.ToLower() == "src")
{
attribute.Value = Regex.Replace(attribute.Value, @"\s*m\s*o\s*c\s*h\s*a\s*", "", RegexOptions.IgnoreCase);
}
}
// HtmlEntity Escape
if (EncodeHtmlEntities)
{
// Ensure no double encoding goes on - reverse the ones done by the CreoleParser
string value = attribute.Value;
value = value.Replace("2", "\"");
value = value.Replace("<", "<");
value = value.Replace(">", ">");
value = value.Replace("&", "&");
value = value.Replace("'", "'");
attribute.Value = value;
StringBuilder sbAttributeValue = new StringBuilder();
foreach (char c in attribute.Value.ToCharArray())
{
sbAttributeValue.Append(EncodeCharacterToHtmlEntityEscape(c));
}
attribute.Value = sbAttributeValue.ToString();
}
}
示例11: Parse
private void Parse()
{
int num = 0;
if (this.OptionComputeChecksum)
this._crc32 = new Crc32();
this.Lastnodes = new Dictionary<string, HtmlNode>();
this._c = 0;
this._fullcomment = false;
this._parseerrors = new List<HtmlParseError>();
this._line = 1;
this._lineposition = 1;
this._maxlineposition = 1;
this._state = HtmlDocument.ParseState.Text;
this._oldstate = this._state;
this._documentnode._innerlength = this.Text.Length;
this._documentnode._outerlength = this.Text.Length;
this._remainderOffset = this.Text.Length;
this._lastparentnode = this._documentnode;
this._currentnode = this.CreateNode(HtmlNodeType.Text, 0);
this._currentattribute = (HtmlAttribute) null;
this._index = 0;
this.PushNodeStart(HtmlNodeType.Text, 0);
while (this._index < this.Text.Length)
{
this._c = (int) this.Text[this._index];
this.IncrementPosition();
switch (this._state)
{
case HtmlDocument.ParseState.Text:
if (!this.NewCheck())
continue;
continue;
case HtmlDocument.ParseState.WhichTag:
if (!this.NewCheck())
{
if (this._c == 47)
{
this.PushNodeNameStart(false, this._index);
}
else
{
this.PushNodeNameStart(true, this._index - 1);
this.DecrementPosition();
}
this._state = HtmlDocument.ParseState.Tag;
continue;
}
continue;
case HtmlDocument.ParseState.Tag:
if (!this.NewCheck())
{
if (HtmlDocument.IsWhiteSpace(this._c))
{
this.PushNodeNameEnd(this._index - 1);
if (this._state == HtmlDocument.ParseState.Tag)
{
this._state = HtmlDocument.ParseState.BetweenAttributes;
continue;
}
continue;
}
if (this._c == 47)
{
this.PushNodeNameEnd(this._index - 1);
if (this._state == HtmlDocument.ParseState.Tag)
{
this._state = HtmlDocument.ParseState.EmptyTag;
continue;
}
continue;
}
if (this._c == 62)
{
this.PushNodeNameEnd(this._index - 1);
if (this._state == HtmlDocument.ParseState.Tag)
{
if (!this.PushNodeEnd(this._index, false))
{
this._index = this.Text.Length;
continue;
}
if (this._state == HtmlDocument.ParseState.Tag)
{
this._state = HtmlDocument.ParseState.Text;
this.PushNodeStart(HtmlNodeType.Text, this._index);
continue;
}
continue;
}
continue;
}
continue;
}
continue;
case HtmlDocument.ParseState.BetweenAttributes:
if (!this.NewCheck() && !HtmlDocument.IsWhiteSpace(this._c))
{
if (this._c == 47 || this._c == 63)
{
this._state = HtmlDocument.ParseState.EmptyTag;
//.........这里部分代码省略.........
示例12: htmlValue
private string htmlValue(HtmlAttribute node)
{
if (node == null)
return String.Empty;
else
return node.Value;
}
示例13: ParsePrefixAttribute
private void ParsePrefixAttribute(RdfAParserContext context, RdfAEvaluationContext evalContext, HtmlAttribute attr, String baseUri, Dictionary<string,Uri> hiddenPrefixes, List<String> inScopePrefixes)
{
//Do nothing if the @prefix attribute is empty
if (attr.Value.Equals(String.Empty)) return;
StringReader reader = new StringReader(attr.Value);
char next;
bool canExit = false;
do
{
StringBuilder prefixData = new StringBuilder();
StringBuilder uriData = new StringBuilder();
//Grab a Prefix - characters up to the next colon
next = (char)reader.Peek();
while (next != ':')
{
//Add the Character and discard it
prefixData.Append(next);
reader.Read();
if (reader.Peek() == -1)
{
this.OnWarning("Aborted parsing a prefix attribute since failed to find a prefix of the form prefix: from the following content: " + prefixData.ToString());
return;
}
else
{
next = (char)reader.Peek();
}
}
//Discard the colon
reader.Read();
//Discard the whitespace
next = (char)reader.Peek();
while (Char.IsWhiteSpace(next))
{
reader.Read();
if (reader.Peek() == -1)
{
this.OnWarning("Aborted parsing a prefix attribute since reached the end of the attribute without finding a URI to go with the prefix '" + prefixData.ToString() + ":'");
return;
}
else
{
next = (char)reader.Peek();
}
}
//Grab the URI - characters up to the next whitespace or end of string
next = (char)reader.Peek();
while (!Char.IsWhiteSpace(next))
{
uriData.Append(next);
reader.Read();
if (reader.Peek() == -1)
{
//End of string so will exit after this
canExit = true;
break;
}
else
{
next = (char)reader.Peek();
}
}
//Now resolve the URI and apply it
String uri = Tools.ResolveUri(uriData.ToString(), baseUri);
if (!(uri.EndsWith("/") || uri.EndsWith("#"))) uri += "#";
String prefix = prefixData.ToString();
if (evalContext.NamespaceMap.HasNamespace(prefix))
{
if (hiddenPrefixes == null) hiddenPrefixes = new Dictionary<string, Uri>();
hiddenPrefixes.Add(prefix, new Uri(uri));
}
evalContext.NamespaceMap.AddNamespace(prefix, new Uri(uri));
inScopePrefixes.Add(prefix);
} while (!canExit);
}
示例14: ParseVocabAttribute
private void ParseVocabAttribute(RdfAParserContext context, RdfAEvaluationContext evalContext, HtmlAttribute attr)
{
if (attr.Value.Equals(String.Empty))
{
//Reset Local Vocabulary
evalContext.LocalVocabulary = new TermMappings(context.DefaultVocabulary);
}
else
{
evalContext.LocalVocabulary.VocabularyUri = attr.Value;
}
}
示例15: Clone
/// <summary>
/// Creates a duplicate of this attribute.
/// </summary>
/// <returns>The cloned attribute.</returns>
public HtmlAttribute Clone()
{
var att = new HtmlAttribute(_ownerdocument) {
Name = Name,
Value = Value
};
return att;
}