Learn R Programming

W3CMarkupValidator (version 0.2-0)

w3c_markup_validate: Validate Markup of Web Documents using W3C Markup Validation Services

Description

Check the markup validity of web documents in HTML, XHTML, etc., using a W3C Markup Validation service.

Usage

w3c_markup_validate(baseurl = w3c_markup_validate_baseurl(),
                    uri = NULL, file = NULL, string = NULL,
                    opts = list(), jar = NULL)

Arguments

baseurl

a character string giving the URL of the W3C Markup Validation service to employ.

uri

a character string giving the URI to validate.

file

a character string giving the path of a file to validate.

string

a character string with the markup to validate.

opts

a named list with options to use for accessing the validation service.

jar

a character string giving the path to a vnu.jar for direct local validation.

Details

Exactly one of uri, file or string must be given.

Validation is then (unless jar is given) performed using the new W3C Markup Validation service at the given URL, as appropriate for programmatic checking of modern HTML (i.e., HTML5) documents. See https://validator.w3.org/docs/api.html for more information.

(Versions of W3CMarkupValidator up to 0.1-7 used the obsolete SOAP 1.2 API for the Markup Validator, which cannot handle HTML5.)

If the validation requests was successful (i.e., a 200 OK response status was returned), w3c_markup_validate() returns the information in the response organized into an object of class "w3c_markup_validate", which is a data frame with with rows giving the diagnostic messages and the following variables:

type

a character string giving the type of the message: one of "info", "error" or "document-error".

subType

a character string giving the subtype of the message. For type "info" this can be "warning" or missing; for type "error" this can be "fatal" or missing.

firstLine, firstColumn, lastLine, lastColumn

integers indicating the range of source code associated with the message.

message

a character string giving the diagnostic message text.

extract

a character string representing an extract of the document source from around the point in source designated for the message by the line and column numbers.

Alternatively, one can also use the underling Nu HTML checker directly (via invoking the Java interpreter) using a local vnu.jar JAR file by giving the path to this file in the jar argument. See https://validator.github.io/validator/ for more information. Using the latest version of vnu.jar from https://github.com/validator/validator/releases/tag/latest works best.

This class has methods for print for compactly summarizing the results, and an inspect method for inspecting details.

See Also

w3c_markup_validate_baseurl for getting and setting the URL of the validation service.

w3c_markup_validate_db for combining and analyzing collections of single validation results.

Examples

Run this code
## Not much to show with this as it should validate ok
## (provided that the validation service is accessible):
tryCatch(w3c_markup_validate(uri = "https://CRAN.R-project.org"),
         error = identity)

Run the code above in your browser using DataLab