我想一个div结束后直接镶嵌一些我自己的HTML。这div有其他分区里面它。
I'm trying to inset some of my own html directly after the end of a div. This div has other div inside of it.
Dim HtmlNode As HtmlNode = HtmlNode.CreateNode("<span class=""label"">Those were the friends</span>")
Dim FriendDiv = htmldoc.DocumentNode.SelectSingleNode("//div[@class='profile_friends']")
Dim NewHTML As HtmlNode = htmldoc.DocumentNode.InsertAfter(HtmlNode, FriendDiv)
我每次运行code我得到一个异常节点&LT; DIV CLASS =profile_topfriends&GT;&LT; / DIV&gt;中在集合中未找到
类似的 的XmlNode
的 InsertAfter()
,你需要调用参考节点的公共父这种方法是插入的节点。尝试是这样的:
Similar to XmlNode
's InsertAfter()
, you need to call this method on the common parent of referenced node and to be inserted node. Try something like this :
Dim NewHTML As HtmlNode = FriendDiv.ParentNode.InsertAfter(HtmlNode, FriendDiv)
正常工作对我来说。下面是一个简单的测试,我在C#中做的事(翻译成VB):
Worked fine for me. Here is a simple test I did in C# (translated to VB) :
Dim html = "<body><div></div></body>"
Dim doc As New HtmlDocument()
doc.LoadHtml(html)
Dim div = doc.DocumentNode.SelectSingleNode("//div")
Dim span = HtmlNode.CreateNode("<span class=""label"">Those were the friends</span>")
Dim newHtml = div.ParentNode.InsertAfter(span, div)
Console.WriteLine(XDocument.Parse(doc.DocumentNode.OuterHtml).ToString())
在&LT;跨度&GT;
之后出现&LT; DIV&GT;
控制台
上一篇:FragmentPagerAdapter的getItem误差ListFragment误差、FragmentPagerAdapter、getItem、ListFragment
下一篇:可DebugDiag资料生成具有&QUOT报告,包括大小和QUOT;如Visual Studio 2013大小、报告、资料、QUOT