This is an AMP version of the article, its original content can be found here.
W3C Java Validators
A few years ago, I created two Java wrappers for W3C validators: (HTML and CSS). Both wrappers seemed to be working fine and were even listed by W3C on their website in the API section. Until recently, these wrappers have always been part of ReXSL library.
A few days ago, though, I took the wrappers out of ReXSL and published them as a standalone library—jcabi-w3c. Consequently, now seems to be a good time to write a few words about them.
Below is an example that demonstrates how you can validate an HTML document against W3C compliance rules:
valid() method is a black or white indicator that
false when the document is not valid. Additionally,
you can obtain more information through a list of "defects" returned by the W3C server:
The same can be done with CSS:
Personally, I think it is a good practice to validate all of HTML pages produced by your application against W3C during integration testing. It's not a matter of seeking perfection, but rather of preventing bigger problems later.
These dependencies are mandatory when using jcabi-w3c (get their latest versions in Maven Central):