brainsteam.co.uk/brainsteam/content/posts/legacy/2015-06-28-tidying-up-xml-i...

31 lines
1.0 KiB
Markdown
Raw Normal View History

2020-12-28 11:39:11 +00:00
---
author: James
2023-07-09 11:34:44 +01:00
date: 2015-06-28 10:24:33+00:00
post_meta:
- date
2024-10-28 20:59:46 +00:00
preview: /social/e899177cd0eed8ffe63cdc3155319b51d261bc84ebf89f74605f8639ad10e46c.png
2020-12-28 11:39:11 +00:00
tags:
2023-07-09 11:34:44 +01:00
- phd
- sapienta
- python
title: Tidying up XML in one click
type: posts
url: /2015/06/28/tidying-up-xml-in-one-click/
2020-12-28 11:39:11 +00:00
---
2023-07-09 11:34:44 +01:00
2020-12-28 11:39:11 +00:00
When I’m working on Partridge and SAPIENTA, I find myself dealing with a lot of badly formatted XML. I used to manually run _xmllint –format_ against every file before opening it but that gets annoying very quickly (even if you have it saved in your bash history). So I decided to write a Nemo script that does it automatically for me.
2022-01-03 14:45:02 +00:00
<pre lang="bash">#!/bin/sh
for xmlfile in $NEMO_SCRIPT_SELECTED_FILE_PATHS; do
if [[ $xmlfile == *.xml ]]
then
xmllint --format $xmlfile > $xmlfile.tmp
rm $xmlfile
mv $xmlfile.tmp $xmlfile
fi
done
2020-12-28 11:39:11 +00:00
</pre>
Pop that in a file called &#8220;Tidy XML&#8221; in your ~/.local/share/nemo/scripts directory and when you inspect files with Nemo it should appear in the right click menu.