CSSOMParser在解析过程中出错



在解析css文件all.css

时出现以下错误
null [1:1763] Error in style rule. Invalid token "!". Was expecting one of: <S>, "}", ",", ";", "/", "+", "-", <HASH>, <STRING>, <URI>, <IMPORTANT_SYM>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMEN>, <PERCENTAGE>, <NUMBER>, "rgb(", <FUNCTION>, <IDENT>, <UNICODERANGE>.
null [1:1763] Ignoring the following declarations in this rule.
null [1:4352] Error in style rule. Invalid token "!". Was expecting one of: <S>, "}", ",", ";", "/", "+", "-", <HASH>, <STRING>, <URI>, <IMPORTANT_SYM>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMEN>, <PERCENTAGE>, <NUMBER>, "rgb(", <FUNCTION>, <IDENT>, <UNICODERANGE>.
null [1:4352] Ignoring the following declarations in this rule.
null [1:4435] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:4435] Ignoring the following declarations in this rule.
null [1:10349] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:10349] Ignoring the following declarations in this rule.
null [1:12131] Error in style rule. Invalid token "!". Was expecting one of: <S>, "}", ",", ";", "/", "+", "-", <HASH>, <STRING>, <URI>, <IMPORTANT_SYM>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMEN>, <PERCENTAGE>, <NUMBER>, "rgb(", <FUNCTION>, <IDENT>, <UNICODERANGE>.
null [1:12131] Ignoring the following declarations in this rule.
null [1:17335] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:17335] Ignoring the following declarations in this rule.
null [1:20115] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:20115] Ignoring the following declarations in this rule.
null [1:20499] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:20499] Ignoring the following declarations in this rule.
null [1:22593] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:22593] Ignoring the following declarations in this rule.
null [1:23137] Error in expression. Invalid token "=". Was expecting one of: <S>, ",", "/", "+", "-", <HASH>, <STRING>, ")", <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMEN>, <PERCENTAGE>, <NUMBER>, "rgb(", <FUNCTION>, <IDENT>, <UNICODERANGE>.
null [1:27252] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:27252] Ignoring the following declarations in this rule.
null [1:28495] Error in style rule. Invalid token "!". Was expecting one of: <S>, "}", ",", ";", "/", "+", "-", <HASH>, <STRING>, <URI>, <IMPORTANT_SYM>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMEN>, <PERCENTAGE>, <NUMBER>, "rgb(", <FUNCTION>, <IDENT>, <UNICODERANGE>.
null [1:28495] Ignoring the following declarations in this rule.
null [1:32022] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:32022] Ignoring the following declarations in this rule.
null [1:33926] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:33926] Ignoring the following declarations in this rule.
null [1:34660] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:34660] Ignoring the following declarations in this rule.
null [1:36410] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:36410] Ignoring the following declarations in this rule.
null [1:36624] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:36624] Ignoring the following declarations in this rule.
null [1:37378] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:37378] Ignoring the following declarations in this rule.
null [1:39110] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:39110] Ignoring the following declarations in this rule.
null [1:40536] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:40536] Ignoring the following declarations in this rule.
null [1:41061] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:41061] Ignoring the following declarations in this rule.
null [1:41487] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:41487] Ignoring the following declarations in this rule.
null [1:45987] Error in expression. Invalid token "=". Was expecting one of: <S>, ",", "/", "+", "-", <HASH>, <STRING>, ")", <URI>, "inherit", <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <DIMEN>, <PERCENTAGE>, <NUMBER>, "rgb(", <FUNCTION>, <IDENT>, <UNICODERANGE>.
null [1:45992] Error in style rule. Invalid token "position". Was expecting one of: "}", ";".
null [1:45992] Ignoring the following declarations in this rule.
null [1:46761] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:46761] Ignoring the following declarations in this rule.
null [1:50353] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:50353] Ignoring the following declarations in this rule.
null [1:51070] Error in style rule. Invalid token "-". Was expecting one of: <S>, "}", ";", <IDENT>.
null [1:51070] Ignoring the following declarations in this rule.

它看起来与破碎的css标签有关。有人能解释一下吗?我使用文件中的css规则来找出html页面上的某些元素(链接到css)。这些错误实际上会影响css规则的解析,从而影响网页上html元素的分析吗?(我确信它有,但希望它没有)

Thanks in advance.

可能是因为你使用了非标准的CSS规则,比如"!或供应商特定的属性,如"-moz-border-radius"?

在解析时必须转义字符。Apache有StringEscapeUtils类可以帮助您。我认为你必须使用StringEscapeUtils.escapeHTML(readedText);,因为html和css语法更相似。

问候!

最新更新