【发布时间】:2009-12-19 21:56:31
【问题描述】:
如何在 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 text”;当我使用setTextContet("someAnotherText"+{bodyNode}.getTextContent()),并序列化这些结构时,结果是<body>someAnotherText sometext text</body>,没有<div>标签。这对我来说是个问题。
【问题讨论】: