Question

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>");
Was it helpful?

Solution

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

    String html = ...; //HTML in String
    html.replaceAll("<!--", "");
    html.replaceAll("-->", "");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top