I just rolled out my own CSS Stream Parser for Java, available on github. What sets this parser apart includes:
- It is a stream parser, so the parser handler will receive notification of all new content immediately after each item has been parsed
- Full support for all currently-documented At-Rules
- Custom classes
TokenSequence
and Token
simplify processes for handling selectors, etc.
- Easy to use and to understand
- Useful for validation or for more advanced applications
- Scalable: designed to be able to handle changes to CSS definitions.
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.