Grunt XML Validator

XML files can be validated using the grunt-xml-validator plugin.

grunt validate xml

Navigate to the root directory of your project and run the command

				
				npm install grunt-xml-validator --save-dev
				
			

The package.json file's devDependencies field will now have a new listing called grunt-xml-validator

				
				  "devDependencies": {
				    "grunt": "^1.0.1",
				    "grunt-xml-validator": "^1.1.3"
				  }
				
			

As an example, let us consider one of the most common XML file to validate, the sitemap.xml file, which is usually located in the root directory of a web project, in the same location where Gruntfile.js is. Below is the set up of the Gruntfile.js

				
				module.exports = function(grunt) {
					grunt.initConfig({
						pkg: grunt.file.readJSON('package.json'),
				        xml_validator: {
				          target: {
				            src: ['sitemap.xml']
				          }
				        }
					});
				  	grunt.loadNpmTasks('grunt-xml-validator');	
				}
				
			

In the last statement, the plugin name grunt-xml-validator is passed as an argument to the grunt.loadNpmTasks() method and called.

Validating sitemap.xml can now be achieved by running the command

				grunt xml_validator
			
grunt-xml-validator plugin