Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 36 Next »

Description / Features

This plugin enables analysis of XML files within Sonar.

Some common use cases are:

  • Validation of XHTML files by using the XHTML schemas as provided by the W3C (strict, transitional, and others). Quickly validate the markup of a set of XHTML files. 
  • Validation of XML files for conformance to the provided XML schema.
  • Validation of rules in XML files (ex: validate the Maven pom files for conformance to coding standards)

Installation

  1. Install the XML plugin through the Update Center or download it into the SONAR_HOME/extensions/plugins directory
  2. Restart the Sonar server

Usage

Run a Sonar Analysis with the Sonar Runner (Recommended Way)

To launch a Sonar analysis of your XML project, use the Sonar Runner.

A sample project is available on github that can be browsed or downloaded: /projects/languages/xml/xml-sonar-runner.

Run a Sonar Analysis with the other Analyzers

Maven and Ant can also be used to launch analysis on Web projects.

Advanced Properties

The following properties of the plugin are configurable:

Property

Description

sonar.xml.includeFileFilter

Additional filter for the files to be scanned

Schema Validation

XmlSchemaCheck Rule

An XmlSchemaCheck rule is available and can be copied and instantiated multiple times. It has two parameters: 

Property

Description

filePattern

Filter for the files to be validated with this check.

schemas

Namespace of schema to use for validation.

Examples:

  • 'xhtml1-strict' for a built-in schema, see the Schemas section for a complete list of available schemas
  • 'schemas/xsd/mycustomschema.xsd' for a schema on filesystem.

If you set the 'schemas' parameter to 'autodetect', the parser will try to load the schema based on the doctype or the namespace declaration in the document.

Schemas

Schema validation is performed by the xerces parser using XML schemas (XSDs). The plugin has a couple of schemas available:

Namespace or Short name

Doctype

Description

http://www.w3.org/2001/xml.xsd

 

XML

http://www.w3.org/1999/xhtml

 

XHTML1.0 Strict

xhtml1-strict

-//W3C//DTD XHTML 1.0 Strict//EN

XHTML1.0 Strict

xhtml1-transitional

-//W3C//DTD XHTML 1.0 Transitional//EN

XHTML1.0Ttransitional

xhtml1-frameset

-//W3C//DTD XHTML 1.0 Frameset//EN

XHTML1.0 Frameset

 

-//W3C//DTD XHTML 1.1 Strict//EN

XHTML1.1

http://java.sun.com/jsf/core

 

JSF core

http://java.sun.com/jsf/html

 

JSF HTML Basic

http://java.sun.com/jsf/facelets

 

JSF Facelets

http://maven.apache.org/POM/4.0.0

 

Maven Project Model

Notes:

  • For validation of XHTML files it is recommended to use autodetect, xhtml1-transitional or xhtml1-strict. 
  • There is no XML schema for HTML 5 provided by W3C.
  • If you need to check with another schema, you can provide the path or URL to the schema. The plugin will search for the schema by URL then fallback on filesystem using a relative path.

XPath Check

The XPath Check allows to specify checks on XML documents using XPath expressions. 

The purpose of the check is to look for nodes and attributes that are not allowed.

The rule has two parameters:

  • expression for the XPath expression
  • filePattern to specify files to be included (e.g. */myfiles/.xml)

Example expressions:

XPath expression

Description

//b

Find all occurrences of <b>

//td[@nowrap]

Find all occurrences of td with the deprecated attribute nowrap

Change Log

Loading

Release 1.0 (not yet released) (15 issues)

 

Loading

Release 0.2 (9 issues)

 

Loading

Release 0.1 (3 issues)

  • No labels