Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transfer .html to .xhtml with java
public class ToXHTML {
/**
* <dependency>
* <groupId>net.sf.jtidy</groupId>
* <artifactId>jtidy</artifactId>
* <version>r938</version>
* </dependency>
*/
@SneakyThrows
private String convertToXhtml(String html) {
Tidy tidy = new Tidy();
tidy.setInputEncoding("UTF-8");
tidy.setOutputEncoding("UTF-8");
tidy.setXHTML(true);
ByteArrayInputStream inputStream = new ByteArrayInputStream(html.getBytes("UTF-8"));
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
tidy.parseDOM(inputStream, outputStream);
return outputStream.toString("UTF-8");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment