Feature #1290

Indentation of output XML files

Added by Brecht De Man almost 9 years ago. Updated almost 9 years ago.

Status:NewStart date:2015-06-19
Priority:NormalDue date:
Assignee:Nicholas Jillings% Done:

0%

Category:-
Target version:-

Description

For nice viewing of the output XML files, some whitespace/indentation is in order. Recent versions of Safari display XML quite nicely, any other text editor I'm using displays everything as a single line. Shouldn't be very hard.

I've got this much in Python to do the same thing (mostly pseudocode) before I realised I'm suppose to write a PhD. And also it would make more sense if the JavaScript just generated it properly from the start.

#!/usr/bin/python

import os

# get every XML file in folder
for file in os.listdir("."): # You have to put this script in folder where output XML files are.
if file.endswith(".xml"):
# read in each line as single string
# for each line:
# at every '<...>'
# increase variable 'indentation'
# enter new line afterwards [if immediately '<' afterwards, or in other words except if next one is corresponding ]
# at every '< / ...>'
# decrease variable 'indentation'
# enter new line afterwards
# at every '<... />'
# enter new line afterwards

(Sorry indentation is not showing in preview)

History

#1 Updated by Brecht De Man almost 9 years ago

  • Description updated (diff)

#2 Updated by Brecht De Man almost 9 years ago

  • Description updated (diff)

#3 Updated by Nicholas Jillings almost 9 years ago

It's standard output for JavaScript to not perform the indentation (as it adds line-breaks and white-space which are for human readability, which adds to transmission size).

It may be useful to get the python server to automatically perform the formatting on receiving the file upload as well as a standalone script

I know Aptana Studio 3 (web IDE) supports re-indenting of files (and compressing files), so if you need something ASAP to do this, then this software will do it. This is how I formatted the XML for the paper.

#4 Updated by Brecht De Man almost 9 years ago

Hm okay, I guess it would be nice to have this in the server Python script (unless there are major disadvantages to having whitespace in the XML file). If I get around to making a Python script to do that (as outlined above) I'll upload it.

#5 Updated by Nicholas Jillings almost 9 years ago

I'll create a stand-alone python script which will monitor this. Perhaps a python server option. Either way then it will be easy to script into other functions by importing it. May also proove useful outside this work as well.

Also available in: Atom PDF