本文整理汇总了C#中HtmlAgilityPack.SetAttributeValue方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlAgilityPack.SetAttributeValue方法的具体用法?C# HtmlAgilityPack.SetAttributeValue怎么用?C# HtmlAgilityPack.SetAttributeValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack
的用法示例。
在下文中一共展示了HtmlAgilityPack.SetAttributeValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateHref
private static void UpdateHref(HtmlAgilityPack.HtmlNode link, Dictionary<string, string> map, Func<string, string> updater)
{
string attribute = "href";
var key = link.GetAttributeValue(attribute, null);
string path;
if (PathUtility.TryGetPathFromWorkingFolder(key, out path))
{
string href;
// For href, # may be appended, remove # before search file from map
var anchorIndex = key.IndexOf("#");
var anchor = string.Empty;
if (anchorIndex == 0) return;
if (anchorIndex > 0)
{
anchor = key.Substring(anchorIndex);
key = key.Remove(anchorIndex);
}
if (map.TryGetValue(key, out href))
{
href = updater(href);
href += anchor;
link.SetAttributeValue(attribute, href);
}
else
{
Logger.Log(LogLevel.Warning, $"File {path} is not found.");
// TODO: what to do if file path not exists?
// CURRENT: fallback to the original one
link.SetAttributeValue(attribute, path);
}
}
}
示例2: UpdateSrc
private static void UpdateSrc(HtmlAgilityPack.HtmlNode link, Dictionary<string, string> map, Func<string, string> updater)
{
string attribute = "src";
var key = link.GetAttributeValue(attribute, null);
string path;
if (PathUtility.TryGetPathFromWorkingFolder(key, out path))
{
string xrefValue;
if (map.TryGetValue(key, out xrefValue))
{
xrefValue = updater(xrefValue);
link.SetAttributeValue(attribute, xrefValue);
}
else
{
Logger.Log(LogLevel.Warning, $"File {path} is not found.");
// TODO: what to do if file path not exists?
// CURRENT: fallback to the original one
link.SetAttributeValue(attribute, path);
}
}
}
示例3: UpdateHref
private static void UpdateHref(HtmlAgilityPack.HtmlNode link, string attribute, IDocumentBuildContext context, string relativePath)
{
var originalHref = link.GetAttributeValue(attribute, null);
var anchor = link.GetAttributeValue("anchor", null);
link.Attributes.Remove("anchor");
string href;
var path = RelativePath.TryParse(originalHref);
if (path?.IsFromWorkingFolder() == true)
{
var targetPath = (RelativePath)context.GetFilePath(path.UrlDecode());
if (targetPath != null)
{
href = (targetPath.RemoveWorkingFolder() - (RelativePath)relativePath).UrlEncode();
}
else
{
Logger.LogInfo($"File {path} is not found in {relativePath}.");
// TODO: what to do if file path not exists?
// CURRENT: fallback to the original one
href = (path.UrlDecode().RemoveWorkingFolder() - (RelativePath)relativePath).UrlEncode();
}
link.SetAttributeValue(attribute, href + anchor);
}
}