0
我有以下html(文檔內容的大小)傳遞給java方法。如何將html片段注入到包含有效html的字符串中?
但是,我想把這個傳遞給html字符串,並添加一個< pre>標記,其中包含一些傳入的文本,並向頭部添加一段< script type =「text/javascript」>。
String buildHTML(String htmlString, String textToInject)
{
// Inject inject textToInject into pre tag and add javascript sections
String newHTMLString = <build new html sections>
}
- htmlString -
<html>
<head>
</head>
<body>
<body>
</html>
- newHTMLString
<html>
<head>
<script type="text/javascript">
window.onload=function(){alert("hello?";}
</script>
</head>
<body>
<div id="1">
<pre>
<!-- Inject textToInject here into a newly created pre tag-->
</pre>
</div>
<body>
</html>
什麼是比從正則表達式的其他Java中做到這一點的最好的工具?
HTML或XHTML?如果後者可以用標準的XML庫來完成。 – nablex
@nablex:html但我認爲一些其他類型的XML解析會工作?可能也是jsoup? – JaJ