# XCOP&mdash;XML Style Checker

Source: https://www.yegor256.com/2017/08/29/xcop.html

One of the biggest advantages of XML versus
[many other]({% pst 2015/nov/2015-11-16-json-vs-xml %}) data formats is that
it is human-readable. Well, to some extent, you may say. Indeed, a badly
formatted XML document may be rather difficult to digest. I'm not talking about
XML [validity](https://en.wikipedia.org/wiki/Well-formed_document)
now, but about its formatting style. Just like we format our
Java/Ruby/Python nicely and then check their "prettiness" with static analyzers,
we can also check our XML documents. Six years ago I asked the Stack Overflow community
for such a tool, but unfortunately
[my question](https://stackoverflow.com/questions/6091873/)
was down-voted and closed
(you will need 10K+ reputation to see it).
Last week I finally decided to create a tool myself and I called it
[xcop](https://github.com/yegor256/xcop).


{% jb_picture_body %}

It's a very simple command line
[Ruby gem](https://rubygems.org/gems/xcop).
First, you install it:

```bash
$ gem install xcop
```

And then you ask it to check your XML file, say `pom.xml`:

```bash
$ xcop pom.xml
```

If the file is not "pretty," `xcop` will complain and
show what's wrong. You can ask `xcop` to fix the file:

```bash
$ xcop --fix pom.xml
```

Moreover, in most cases you may need your XML files to include a license
in their headers, especially if it's open source. To enforce that, just
point `xcop` to the file with the license:

```bash
$ xcop --license=LICENSE.txt pom.xml
```

I believe it's good practice to use `xcop` together with
Checkstyle (for Java files), Rubocop (for Ruby files), and other static
analyzers, to ensure that your XML files always look pretty.

[Read](https://github.com/yegor256/xcop) how you can integrate `xcop` with
[Rake](https://github.com/ruby/rake),
[Maven](https://maven.apache.org/), and other builders.
I will appreciate it if you contribute your own integrations too.
