0

I have an HTML file in which all tags are in one line. I would like to separate each tag and put it on its own line. The end goal is to have a well-formed HTML file.

e.g.

<html><head><title>StackOverflow</title></head><body></body></html>

would be converted into:

<html>
    <head>
        <title>
        StackOverflow
        </title>
    </head>
    <body>
    </body>
</html>

Is there an existing Java library that handles this already?

Jay
  • 18,959
  • 11
  • 53
  • 72
Hadi
  • 21
  • 3
  • 7

1 Answers1

2

Your problem has nothing to do with well-formed HTML files. Even if html tags are on the same line, doesn't mean that the html is not well formed. What you actually neeed is just a formatter, which basically will make your html more human-readable. You could take a look at JTidy, which can optionally do also a syntax checking.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
loscuropresagio
  • 1,922
  • 15
  • 26