如何更改Java中的HTML標籤內容?例如:如何更改Java中的HTML標記內容?
前:
<html>
<head>
</head>
<body>
<div>text<div>**text**</div>text</div>
</body>
</html>
後:
<html>
<head>
</head>
<body>
<div>text<div>**new text**</div>text</div>
</body>
</html>
我試過JTidy,但它不支持getTextContent
。還有其他解決方案嗎?
謝謝,我想解析沒有格式良好的HTML。我試過TagSoup,但是當我有這樣的代碼:
<body>
sometext <div>text</div>
</body>
,我想改變「SomeText」則會以「someAnotherText,」當我使用{bodyNode}.getTextContent()
它給了我:「sometext文本」;當我使用setTextContet("someAnotherText"+{bodyNode}.getTextContent())
,並對這些結構進行序列化時,結果爲<body>someAnotherText sometext text</body>
,而沒有<div>
標籤。這對我來說是個問題。
我e.get需要更多的澄清第一個孩子();返回節點,那麼你怎麼聲明元素「Element text = e.getFirstChild();」...請澄清我@Dmitry ...謝謝 – 2016-06-22 12:39:24
setNodeValue和getNodeValue在Node.Thanks中定義,用於引起注意返回類型。 – Dmitry 2016-06-23 13:21:18
但你沒有定義'process(..)'方法。 – 2018-03-08 02:08:49