Jsoup: How to convert a String containing HTML to a XHTML document?

好久不见. 提交于 2019-12-11 03:36:41

问题


Title says it all. How to do that with Jsoup? I don't need a file. Just XHTML to use. I've only found some examples with bytearrays and fileoutputs. I only need a valid XHTML to use with itext PdfWriter and XMLWorker later on.


回答1:


I believe something like this would do the trick

Document doc = Jsoup.parse(html);
doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml); //This will ensure the validity
doc.outputSettings().charset("UTF-8");
System.out.println(doc);


来源:https://stackoverflow.com/questions/28876603/jsoup-how-to-convert-a-string-containing-html-to-a-xhtml-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!