sclable / xml-lint
A php cli tool to lint and validate xml files.
Requires
- php: ^8.2
- ext-dom: *
- ext-libxml: *
- symfony/console: ^7.4 || ^8.1
- symfony/finder: ^7.4 || ^8.1
Requires (Dev)
- behat/behat: ^4.0
- phpunit/phpunit: ^11.5 || ^12.5 || ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A php tool to lint and validate xml files from the commandline.
XML Lint checks the syntax of any xml files and validates the file against the XSD schema defined in the file.
Requirements
- PHP 8.2 or newer with the
domandlibxmlextensions - symfony/console and symfony/finder 7.4 or 8.1+
Usage
Installation with Composer
composer require --dev sclable/xml-lint
Command Line Usage
To lint a single xml file:
vendor/bin/xml-lint path/to/file.xml
To lint a directory and all its subdirectories:
vendor/bin/xml-lint path/to/dir
The tool is installed as vendor/bin/xml-lint and vendor/bin/xmllint. Both do the same.
xmllint is also the name of the libxml2 command line tool (/usr/bin/xmllint), so if
vendor/bin is on your PATH, use xml-lint to avoid mixing them up.
Help
vendor/bin/xml-lint --help
Options
-r,--recursive[=yes|no]scan subdirectories (default). Use-r 0,-r false,-r noor-r offto lint only the top directory-e,--exclude=dir1,dir2skip directories, by name or by path relative to the given directory-p,--pattern=*.xml,*.svgonly lint files that match one of the patterns (default:*.xmland*.xml.dist)-s,--skip-xsdonly check the syntax, don't validate against the XSD schema-vshow each file name and its result-qonly show errors--silentshow nothing, only set the exit code
-r, -e and -p only apply when the argument is a directory.
Exit codes
0all files are valid1at least one file has problems, or the arguments are invalid
Public API
The command line (options, arguments and exit codes) is the public API and follows semantic versioning. The PHP classes are internal and can change in any release.
Development
Install
composer install composer install --working-dir=tools/php-cs-fixer composer install --working-dir=tools/phpstan
Code style
# check composer cs # fix composer cs:fix
Static analysis
composer phpstan
Run tests
# all tests composer test # unit tests (PHPUnit) composer test:unit # functional tests (Behat) composer test:functional
Using docker:
# Example docker build -t xml-lint:php-8.4 --build-arg=PHP_VERSION="8.4" . # PHP_VERSION: choose between 8.2, 8.3, 8.4 and 8.5 (default: 8.4) docker build -t xml-lint:php-8.2 --build-arg=PHP_VERSION="8.2" . docker build -t xml-lint:php-8.3 --build-arg=PHP_VERSION="8.3" . docker build -t xml-lint:php-8.4 --build-arg=PHP_VERSION="8.4" . docker build -t xml-lint:php-8.5 --build-arg=PHP_VERSION="8.5" . # Run with code style check docker build -t xml-lint:php-8.4 --build-arg=PHP_VERSION="8.4" --build-arg=PHP_CS_FIXER=true . # Use this image to run xml-lint: cd tests/functional/_testdata docker run -it --rm -v "$PWD":/var/src -w /var/src xml-lint:php-8.4 -v .
Changelog
For the changelog see the CHANGELOG file
License
For the license and copyright see the LICENSE file