Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

SnapLogic is the leading self-service enterprise-grade integration platform. Download the 2018 GartnerMagic Quadrant for Enterprise iPaaS or play around on the platform, risk free, for 30 days.

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.

Download A Buyer's Guide to Application and Data Integration, your one-stop-shop for research, checklists, and explanations for an application and data integration solution.

Topics:
static ,data ,stackoverflow ,xml ,style ,integration

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}