类 html 文本,看起来像:
Simple<br> text <b>simple</b> text simple <BR><BR>text simple text
, 我想解析它并创建 dom document .但问题在于未关闭的标签,当我尝试这样做时:
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource source = new InputSource(new StringReader(
Document doc = builder.parse(source);
发生错误:org.xml.sax.SAXParseException; The element type "br" must be terminated by the matching end-tag
我不想全部替换 <br>
通过 <br></br>
,任何解决方案或建议?
最佳答案
使用jsoup并享受易用性。
关于java - 如何在java中解析准html文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17988846/