When I get to work with xml they are usually all on one row. This makes it impossible (or at least very hard) to read them. One solution I found was the superb –format option. This option will make the xmllint program to output the one row xml to a multiple nice print xml document.
Example
Our ugly one row xml (ugly.xml):
<?xml version="1.0" encoding="utf-8"?><movies><movie><title>The Brave One</title><genre>Thriller</genre></movie><movie><title>Instinct</title><genre>Drama</genre></movie></movies>
Run the command:
xmllint --format ugly.xml
or(if no file):
echo '<?xml version="1.0" encoding="utf-8"?><movies><movie><title>The Brave One</title><genre>Thriller</genre></movie><movie><title>Instinct</title><genre>Drama</genre></movie></movies>' | xmllint --format -
And you get:
<?xml version="1.0" encoding="utf-8"?> <movies> <movie> <title>The Brave One</title> <genre>Thriller</genre> </movie> <movie> <title>Instinct</title> <genre>Drama</genre> </movie> </movies>
Much better!
Pipe result into Vim
xmllint --format ugly.xml | vim -
Note the last ‘-‘ sign as it tells vim to read input from standard input.
0 Comments.