Htmlの敏捷性パックを使用したMS Wordのタグをストリップ
-
22-09-2019 - |
質問
私はMS Wordから貼り付けた一部のテキストフィールドでDBを持っている、と私は彼らのinnerTextを保ち、明らかにだけ、とタグを除去するために問題が発生したが、しています。
私はHAPを使用してみましたが、私は正しい方向に向かっていないよ..
Public Function StripHtml(ByVal html As String, ByVal allowHarmlessTags As Boolean) As String
Dim htmlDoc As New HtmlDocument()
htmlDoc.LoadHtml(html)
Dim invalidNodes As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//div|//font|//span")
For Each node In invalidNodes
node.ParentNode.RemoveChild(node, False)
Next
Return htmlDoc.DocumentNode.WriteTo()
End Function
このコードは、単に目的の要素を選択し、それらを削除します...が、その内部テキストを保っていない..
事前に感謝します。
解決
うーん...私は解決策を見つけたと思います
Public Function StripHtml(ByVal html As String) As String
Dim htmlDoc As New HtmlDocument()
htmlDoc.LoadHtml(html)
Dim invalidNodes As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//div|//font|//span|//p")
For Each node In invalidNodes
node.ParentNode.RemoveChild(node, True)
Next
Return htmlDoc.DocumentNode.WriteContentTo
End Function
私は...ほとんどだった:P
所属していません StackOverflow