Java 关于cssparser
朋友们,我正在使用cssparser解析我的CSS。我的代码如下:Java 关于cssparser,java,css,Java,Css,朋友们,我正在使用cssparser解析我的CSS。我的代码如下: public static Map<String, CSSStyleRule> parseCSS1() throws IOException { Map<String, CSSStyleRule> rules = new LinkedHashMap<String, CSSStyleRule>(); InputSource inputSource = new InputSour
public static Map<String, CSSStyleRule> parseCSS1() throws IOException {
Map<String, CSSStyleRule> rules = new LinkedHashMap<String, CSSStyleRule>();
InputSource inputSource = new InputSource(new FileReader("C:\\COMPUTERS.css"));
CSSStyleSheet styleSheet = new CSSOMParser().parseStyleSheet(inputSource, null, null);
CSSRuleList ruleList = styleSheet.getCssRules();
for (int i = 0; i < ruleList.getLength(); i++) {
CSSRule rule = ruleList.item(i);
if (rule.getType() == CSSRule.STYLE_RULE) {
CSSStyleRule styleRule = (CSSStyleRule) rule;
rules.put(styleRule.getSelectorText(), styleRule);
}
}
return rules;
}
在最后一行中,border:no
后面没有分号,在原始CSS中它是存在的
那么,我应该手动添加分号还是犯了错误
另外,在原始CSS中:
background-color: #FFB6C1
替换为:
background-color: rgb(255, 182, 193);
在解析的输出中。有什么办法可以保持原样吗?CSS声明中的最后一个分号不是强制性的,它被库故意省略了
background-color: rgb(255, 182, 193);