Is there any tool that can (pretty-print) format XML file as well as sort both its elements and attributes?
I liked this tool: https://xmlsorter.codeplex.com/
You can sort by tag name and attributes. I like to use it before comparing some XML files.
I was looking for a similar utility and didn't really find what I was looking for, so I just barely wrote one instead. It's very simple (and doesn't include attributes in node sorting), but works.
Maybe it'll be useful to others.. It's on GitHub.
Here's a bit from the GitHub page...
USAGE: sortxml.exe [options] infile [outfile] infile The name of the file to sort, etc. outfile The name of the file to save the output to. If this is omitted, then the output is written to stdout. OPTIONS: --pretty Ignores the input formatting and makes the output look nice. --sort Sort both the nodes and attributes. --sortnode Sort the nodes. --sortattr Sort the attributes. (prefix an option with ! to turn it off.)
The default is to output pretty and sorted nodes and attributes. Here is an example:
> type sample.xml <?xml version="1.0" encoding="utf-8" ?><root><node value="one" attr="name"/></root> > sortxml.exe sample.xml <?xml version="1.0" encoding="utf-8"?> <root> <node attr="name" value="one" /> </root>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With