如何解决敏捷包:获取自定义标签后代的问题
我有以下HTML模板和以下C#代码:
<div class="DataTag">
<_DATA_ customAttribute="Dummy=Foo" />
</div>
public List<string> GetDataAttribute(string template,string tag,string attrName)
{
var htmlDocument = new HtmlAgilityPack.HtmlDocument();
htmlDocument.LoadHtml(template);
var stringList = new List<string>();
var descendants = htmlDocument.DocumentNode.Descendants(tag);
foreach (var descendant in descendants)
stringList.Add(descendant.GetAttributeValue(attrName,string.Empty));
return stringList;
}
它的调用方式是:
var dataAttribute = this.GetDataAttribute(template,"_DATA_","customAttribute");
“模板”是我作为参数传递的HTML模板。
我的问题是集合“后代”为空。我希望将 DATA 标记作为后代返回,这样我就可以获得属性的值。我找不到原因。否则如何获得例外结果?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。