Hi @pieter, many thanks for your answer.
I have to export stuff selecting elements in the Sketch file. So then I have 2 choices:
1. Create an internal plugin
2. Read the JSON file, create a clickable overview, select the elments I have to export and then create the XML.
Our XML is a bit complex and I have to personalise the plugin a lot.
At the moment I'm able to export quite good Rectangles, Ovals and Texts (good for our XML, not for a perfect export standard, unfortunately): I'm not able to export symbols and symbols contents or to do a recursive export for all the elements inside a group (that for me is the basic view I have to export): all the groups with a fixed prefix "view_" are my root XML elements (with all the child with X and Y as an offset based on the View one).
About the formatting question, I found a solution (I don't know if it's the right one, I just tested and tested) and I posted it on the StackOverflow page itself.