I am currently working with XML files that contain elements with a long list of attributes. When I try to re-indent the whole XML file using xmllint --format myfile.xml only the elements are indented, the attributes still remain in one single line.

Is there some (command line, Windows or GNU/Linux) program that supports re-formatting of XML including the attributes?

For example a XML like:

  <node attribute1="some long attribute value" attribute2="some long attribute value" attribute3="..."/>

should be output similar to:

  <node attribute1="some long attribute value"
        attribute2="some long attribute value"
  • "Command line" doesn't give us enough information. Always, always provide the exact operating system you are running whenever you ask a question that is in any way related to software. This must include the name of the operating system, the version, and any other relevant information such as whether it's 32 or 64-bit. Sep 26, 2012 at 13:29
  • I have Windows and GNU/Linux available so both would be fine. I have updated the question regarding that.
    – blerontin
    Sep 26, 2012 at 13:35
  • You might be able to find what you're looking for here on StackOverflow. Getting the output exactly the way you want it may involve writing a program using an XML parser/generator. Sep 26, 2012 at 13:39
  • The XMLTidy he's referring to is here I believe. Sep 26, 2012 at 13:41

1 Answer 1


While your well-intentioned search for a "command-line tool" is perfectly fine, unfortunately I think any truly viable solution to this problem is going to involve writing some code yourself, or at least leveraging existing code (such as an XML parser/generator). In the comments, have posted a few things you can try that may or may not get you the exact formatting style you're looking for. If it's really close but not quite, your best bet is probably to edit the source code of the program that "almost" gets there. Of course, if you don't know any programming languages, that can be a bit of an impasse.

I am calling all of these solutions "possible" because, even if they format attributes the way you want them to, they might format something else in a way you don't want, and then you're back to square one. Since you didn't state your full transformation requirements, I can only guess at which of these would be acceptable to you, so you'll just have to try them one by one until you either stumble upon something that works, or create it yourself by leveraging existing code and writing a small-ish program.

Possible Solutions Without Programming


Command Line

  • XMLTidy (last updated 2005; may be stale)
  • Dom4j (included here because the "programming" is already given to you in its entirety in the SO answer)

Possible Solutions With Programming

  • Write your own custom program using one of the following:
  • Xerces
  • Dom4j
  • Sax
  • libxml
  • The underlying libraries that Eclipse uses to parse XML, which probably would allow you to programmatically format XML and set up the customized formatting rules as you see in the Eclipse options

... which processes the XML in exactly the way you want it to.

See Also this SO question.

Lastly, note that if you want community help about delving head-first into writing a program involving one of these technologies, you should ask the question specific to one chosen XML parser/generator/library on StackOverflow and not on SuperUser. We primarily deal with questions about usage of existing programs, here.

  • The Eclipse XML Editor seems to be my closest option. Do you know if it is available as some kind of stand-alone application?
    – blerontin
    Sep 26, 2012 at 15:02
  • See this question which I asked on SO to try and get some insight into that very question. Sep 26, 2012 at 15:26
  • OK, my Java knowledge is a bit too low to be able to utilize that classes and write some kind of simple stand-alone application. I guess I will have to install Eclipse.
    – blerontin
    Sep 27, 2012 at 9:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .