Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html to xhtml conversion in java

Tags:

java

how can we convert html to well formed xhtml by using Http class api,if possible please give a demonstration code....thanks

like image 856
yagnya Avatar asked May 09 '11 11:05

yagnya


People also ask

What is XHTML how does XHTML differ from HTML?

HTML is the standard markup language for creating web pages, while XHTML is a stricter and more standardized version of HTML. Both HTML and XHTML include a wide range of features, such as support for multimedia, styling, and scripting.

Can you convert Java to HTML?

Find and select the JAVA files on your computer and click Open to bring them into Doxillion to convert them to the HTML file format. You can also drag and drop your JAVA files directly into the program to convert them as well.


2 Answers

I just did it using Jsoup, if it works for you:

private String htmlToXhtml(final String html) {
    final Document document = Jsoup.parse(html);
    document.outputSettings().syntax(Document.OutputSettings.Syntax.xml);
    return document.html();
}

Some useful content where my solution came from:

  • Is it possible to convert HTML into XHTML with Jsoup 1.8.1?
  • http://developers.itextpdf.com/question/how-do-html-xml-conversion-generate-closed-tags
like image 172
Vitor Pelizza Avatar answered Oct 26 '22 10:10

Vitor Pelizza


Have a look at J-Tidy: http://jtidy.sourceforge.net/ It usually does a quite good job cleaning up messy html and converting it to xhtml.

like image 40
mglauche Avatar answered Oct 26 '22 10:10

mglauche