Thursday, May 5, 2011

How can I use Java to programmaticaly convert an Internal Stylesheet of a web-page to an inline one?

Is there a ready-made tool or utility that does that already

From stackoverflow
  • You could just open the CSS file and just embed its content into a style tag.

    It should not be that hard:

    FileReader frCSS = new FileReader("your_css.css");
    FileReader frHTML = new FileReader("your_html.html");
    FileWriter output = new FileWriter("result.html");
    

    Then parse frHTML and copy its content to output until you find the head opening tag. When you do, open a style tag and copy all contents from frCSS. Then, close the style tag and copy the remaining portion of frHTML.

    It's not pretty, but it can be done.

    Oren Yosifon : That would convert an External Stylesheet to Internal. I am interested in converting internal to inline, if possible, without the heavylifting of doing all the parsing myself...

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.