Skip to content

Instantly share code, notes, and snippets.

@rieckpil
Created April 8, 2018 08:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rieckpil/105477db9bde98649cb0274863214e17 to your computer and use it in GitHub Desktop.
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