Created
April 8, 2018 08:52
-
-
Save rieckpil/105477db9bde98649cb0274863214e17 to your computer and use it in GitHub Desktop.
Transfer .html to .xhtml with java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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