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>");

Answers


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

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

Need Your Help

"gem install mysql2" on Mac with MAMP 2.2

mysql ruby-on-rails macos gem mamp

When trying to run a rails server in my current directory (which is a new rails project), it says that I need to install the mysql2 gem. At first, I had no idea what this meant... Then, I did some ...

Cannot get data from file

java io file-handling randomaccessfile eofexception

Using JFileChooser to save file and everything works perfect: