dascolagi
dascolagi

Reputation: 157

Uncomment HTML code in Java

I need to uncomment CSS code inside a style element (and I need to do this in Java). Consider the following html code:

<html>
<head>
<style type="text/css">
<!--
   .big {
      font-size: 30px;
   }
-->
</style>
</head>
<body></body>
</html>

Here is the desired result:

<html>
<head>
<style type="text/css">
   .big {
      font-size: 30px;
   }
</style>
</head>
<body></body>
</html>

I usually use Jericho to do HTML parsing.

UPDATE. Solved:

String newHtmlString = htmlString.replaceAll("<style><!--", "<style>").replaceAll("--></style>", "</style>");

Upvotes: 0

Views: 165

Answers (1)

TheWalkingCube
TheWalkingCube

Reputation: 2116

If the only comment in your file is CSS comment, you might consider something like :

    String html = ...; //HTML in String
    html.replaceAll("<!--", "");
    html.replaceAll("-->", "");

Upvotes: 3

Related Questions