jStyleParser是一个开源Java的CSS解析器,可以在Java程序中解析CSS样式文件。
Maven
<dependency> <groupId>net.sf.cssbox</groupId> <artifactId>jstyleparser</artifactId> <version>3.2</version></dependency>示例代码:
//get the element styleStyleMap map = CSSFactory.assignDOM(doc, encoding, base, medium, true);NodeData style = map.get(element);//get the type of the assigned valueCSSProperty.Margin mm = style.getProperty("margin-top");System.out.println("margin-top=" + mm);//if a length is specified, obtain the exact valueif (mm == Margin.length){ TermLength mtop = style.getValue(TermLength.class, "margin-top"); System.out.println("value=" + mtop);}
评论