Over a million developers have joined DZone.

XCOP - XML Style Checker

DZone's Guide to

XCOP - XML Style Checker

There's a new XML style checker in town and we take a look at what it is and how to use it for static code analysis in this post.

· Integration Zone
Free Resource

The Integration Zone is brought to you in partnership with Cloud Elements.  What’s below the surface of an API integration? Download The Definitive Guide to API Integrations to start building an API strategy.

One of the biggest advantages of XML versus many other 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 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 StackOverflow community for such a tool, but unfortunately, my question 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.

It's a very simple command line Ruby gem. First, you install it:

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

$ 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:

$ 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:

$ 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 how you can integrate xcop with Rake, Maven, and other builders. I will appreciate it if you contribute your own integrations too.

The State of API Integration Report provides data from the Cloud Elements platform and will help all developers navigate the recent explosion of APIs and the implications of API integrations to work more efficiently in 2017 and beyond.

static ,data ,stackoverflow ,xml ,style ,integration

Published at DZone with permission of Yegor Bugayenko, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}