Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML sorting/formatting tool [closed]

Tags:

Is there any tool that can (pretty-print) format XML file as well as sort both its elements and attributes?

like image 604
Andrey Adamovich Avatar asked Sep 14 '09 21:09

Andrey Adamovich


2 Answers

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.

XML Sorter main window

like image 110
Akira Yamamoto Avatar answered Sep 29 '22 07:09

Akira Yamamoto


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> 
like image 30
kodybrown Avatar answered Sep 29 '22 07:09

kodybrown