Is there anything like Jsoup but instead of parsing HTML, I need to parse CSS, is there a parser similar to that that will create a Document model of a CSS? That perhaps can be used to iterate to nodes?
What I need to do is to find and replace "url" in the CSS file. And with html this is quite easy with Jsoup. However I am not sure if this will be possible with CSS.
If there are no such parser exist what are the options?
Perhaps this might help you?
I just rolled out my own CSS Stream Parser for Java, available on github. What sets this parser apart includes:
TokenSequence and Token simplify processes for handling selectors, etc.For your problem, just use the basic parsing technique:
try
{
//First get the input stream. For example, from a file
InputStream is = new FileInputStream(new File("/path/to/my/CSS/main.css"));
//Then parse
CSSParser parser = new CSSParser(is, new DefaultCSSHandler());
parser.parse();
}
catch (Throwable t)
{
t.printStackTrace();
}
but override some methods in DefaultCSSHandler to look for the identifier you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With