Giter Club home page Giter Club logo

w3cvalidator's Introduction

w3cValidator

Java library to call W3C Validator check

Travis (.org) Maven Central GitHub issues GitHub issues GitHub BITPlan

Documentation

Maven dependency

Maven dependency

<dependency>
  <groupId>com.bitplan</groupId>
  <artifactId>w3cValidator</artifactId>
  <version>0.0.5</version>
</dependency>

Current release at repo1.maven.org

How to build

git clone https://github.com/WolfgangFahl/w3cValidator
cd w3cValidator
mvn install

Purpose

At http://validator.w3.org/ the W3C offers an online validation service for checking html code to be standard compliant. There is also an API available that is described at http://validator.w3.org/docs/api.html

This is a Java Library to call this API. The url of the service may be the official w3c validator at http://validator.w3.org/check or a copy of this service installed in your own environment.

How to use

This java Library calls the W3C Validator according to

Example:

To check some html code with an unclosed div tag with the validator at w3.org:

  // url to use - modify if you have your own installation
  public static final String url="http://validator.w3.org/check";
  
  // html code to check
  String html="<!DOCTYPE html>\n"+
    "<html>\n"+
    "  <head>\n"+
    "    <title>test W3CChecker</title>\n"+
    "  </head>\n"+
    "  <body>\n"+
    "    <div>\n"+
    "  </body>\n"+
    "</html>";
    
  // API call 
	W3CValidator checkResult = W3CValidator.check(url, html);

The returned W3CValidator object has the structure of the SOAP-Response as outlined in http://validator.w3.org/docs/api.html

e.g. checkResult.body.response.errors.errorlist will contain a list of ValidationErrors with line col and message for each error.

Example Output (from JUnit tests):

Validation result for test 1:
	ValidationError line 10 col 9:'end tag for "DIV" omitted, but its declaration does not permit this'
	ValidationWarning line 0 col 0:'Using Direct Input mode: UTF-8 character encoding assumed'

Validation result for test 2:
	ValidationError line 1 col 82:'End tag for  body seen, but there were unclosed elements.'
	ValidationError line 1 col 75:'Unclosed element div.'
	ValidationWarning line 0 col 0:'No Character encoding declared at document level'
	ValidationWarning line 0 col 0:'Using Direct Input mode: UTF-8 character encoding assumed'

Version history

Version date changes
0.0.1 2014-09-22 first published version
0.0.2 2014-09-26 fixes issue with 0x0 unicode in html
0.0.3 2016-06-15 upgrades jersey to 1.19.1 and eclipselink to 2.6.3
0.0.4 never published
0.0.5 2018-08-22 upgrades to Java8, changes License to Apache, improves README, upgrades Libraries

w3cvalidator's People

Contributors

wolfgangfahl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

w3cvalidator's Issues

License question

Hi,

The project's readme indicates the license is GPL 3.0.
However, the license file mentions LGPL 3.0. Could you clarify this?

Thanks!

trailing unicode 0 leads to UmarshalException

a testdocument preamble+footer+"\u0000" will lead to:
javax.xml.bind.UnmarshalException

  • with linked exception:
    [Exception [EclipseLink-25004](Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.XMLMarshalException
    Exception Description: An error occurred unmarshalling the document
    Internal Exception: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[65,87]
    Message: Ungültiges XML-Zeichen (Unicode: 0x0) wurde im CDATA-Abschnitt gefunden.]
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.handleXMLMarshalException(JAXBUnmarshaller.java:980)
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:588)
    at org.eclipse.persistence.jaxb.JAXBUnmarshaller.unmarshal(JAXBUnmarshaller.java:182)
    at com.bitplan.w3ccheck.W3CValidator.check(W3CValidator.java:168)
    at com.bitplan.w3ccheck.TestW3CValidator.testW3CValidator(TestW3CValidator.java:55)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.