本文整理汇总了C#中HtmlAgilityPack.HtmlNode.CloneNode方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.CloneNode方法的具体用法?C# HtmlNode.CloneNode怎么用?C# HtmlNode.CloneNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNode
的用法示例。
在下文中一共展示了HtmlNode.CloneNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Entitize
/// <summary>
/// Clone and entitize an HtmlNode. This will affect attribute values and nodes' text. It will also entitize all child nodes.
/// </summary>
/// <param name="node">The node to entitize.</param>
/// <returns>An entitized cloned node.</returns>
public static HtmlNode Entitize(HtmlNode node)
{
if (node == null)
{
throw new ArgumentNullException("node");
}
HtmlNode result = node.CloneNode(true);
if (result.HasAttributes)
Entitize(result.Attributes);
if (result.HasChildNodes)
{
Entitize(result.ChildNodes);
}
else
{
if (result.NodeType == HtmlNodeType.Text)
{
((HtmlTextNode) result).Text = Entitize(((HtmlTextNode) result).Text, true, true);
}
}
return result;
}
示例2: Entitize
/// <summary>
/// Clone and entitize an HtmlNode. This will affect attribute values and nodes' text. It will also entitize all child nodes.
///
/// </summary>
/// <param name="node">The node to entitize.</param>
/// <returns>
/// An entitized cloned node.
/// </returns>
public static HtmlNode Entitize(HtmlNode node)
{
if (node == null)
throw new ArgumentNullException("node");
HtmlNode htmlNode = node.CloneNode(true);
if (htmlNode.HasAttributes)
HtmlEntity.Entitize(htmlNode.Attributes);
if (htmlNode.HasChildNodes)
HtmlEntity.Entitize(htmlNode.ChildNodes);
else if (htmlNode.NodeType == HtmlNodeType.Text)
((HtmlTextNode) htmlNode).Text = HtmlEntity.Entitize(((HtmlTextNode) htmlNode).Text, true, true);
return htmlNode;
}
示例3: GetNodeIndex
/// <summary>
/// Gets a given node from the list.
/// </summary>
public int this[HtmlNode node]
{
get
{
int index = GetNodeIndex(node);
if (index == -1)
{
throw new ArgumentOutOfRangeException("node", "Node \"" + node.CloneNode(false).OuterHtml + "\" was not found in the collection");
}
return index;
}
}
示例4: SectionizeNodes
/**********************************************************************/
private void SectionizeNodes(HtmlNode node, ref List<DocumentSection> documentSections)
{
foreach (HtmlAttribute hat in node.Attributes)
{
if (hat.Name == "id" && !string.IsNullOrEmpty(hat.Value))
{
DocumentSection ds = new DocumentSection();
ds.SectionNode = node.CloneNode(true);
;
ds.title = hat.Value;
documentSections.Add(ds);
}
}
foreach (HtmlNode child in node.ChildNodes)
{
SectionizeNodes(child, ref documentSections);
}
}