Re: validate from a Java program: how to send CSS and receive results

Hi Erik,

I do not think you are doing anything wrong, actually.
Your code works fine when I change the target URL to target some other 
validator.
The CSS validator must be expecting something it doesn't get, not sure 
what it is.

Depending on what you actually want to do with the results returned by 
the CSS validator, you may consider using the CSS validator directly 
within your project instead of sending an HTTP request.

Instructions to get the source code of the CSS validator are available at:
  http://jigsaw.w3.org/css-validator/DOWNLOAD.html

In particular, a JAR package of the CSS validator is available at:
  http://www.w3.org/QA/Tools/css-validator/css-validator.jar

Once your project references the JAR, all you need to do is to create an 
instance of:
  org.w3c.css.css.StyleSheetParser

... and use its "parseStyleElement" method, after having initialized an 
application context (ApplContext) with the validation settings you need 
(encoding, CSS validation level, language, ...)

You can find code that just about the same thing in the source of the 
mobileOK Checker, in the CSSUtils#getStylesheet method:
 
http://dev.w3.org/cvsweb/2007/mobileok-ref/src/org/w3c/mwi/mobileok/basic/CSSUtils.java?rev=1.29&content-type=text/x-cvsweb-markup

(Please note that some settings and classes used in those lines are 
rather specific to the mobileOK Checker, but that should give you a 
rough idea about how this can be done).

HTH,
Francois.

Received on Monday, 11 January 2010 12:23:54 UTC