Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

Let's face it, currently, the most used formats for transactions and sending information among systems are JSON and XML. From my personal perspective JSON is a better option when we need to use REST services, because:

  1. JSON is a lighter format.
  2. Most of the times we consume REST services from client-side -JavaScript-, using AJAX calls.
  3. Old and modern browsers can parse and transform JSON objects into JavaScript object with almost no work from our side.

The problem

But... sometimes, we need to use XML format and many times we download the XML responses to our local environment to understand its structure, and here is the little problem, browsers don't format XML when we download a response. Let's see an example:

Imagine you have this response:

Code Block
languagehtml/xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><response><status><timeStamp>1395932927084</timeStamp><error_code>0</error_code><error_description></error_description><error_message></error_message><api_version>1.0</api_version></status><data><content><id>id_of_a_post</id><name>Learning-jQuery</name><title>Learning jQuery</title><description></description><summary></summary><image>/path/to/image/image.jpg</image><image_size>143591</image_size><thumbnail>/path/to/image/thumbnail.jpg</thumbnail><published_on>1385355600000</published_on></content></data></response>

Solution

Sublime Text 2 has a really good plugin to format XML files with a single click! Here is the plugin: SublimeText Indent plugin.

Tip

This plugin also works for JSON format.

 

  1. Open your Package Control (if you have never used Package Control, please see this documentation)
  2. Type Indent
  3. Click on the link/option 
  4. Wait for installation's finalization
  5. You will have a new option in Selection menu

After click on Indent XML you will see something like:

Code Block
languagehtml/xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response>
	<status>
		<timeStamp>1395932927084</timeStamp>
		<error_code>0</error_code>
		<error_description/>
		<error_message/>
		<api_version>1.0</api_version>
	</status>
	<data>
		<content>
			<id>id_of_a_post</id>
			<name>Learning-jQuery</name>
			<title>Learning jQuery</title>
			<description/>
			<summary/>
			<image>/path/to/image/image.jpg</image>
			<image_size>143591</image_size>
			<thumbnail>/path/to/image/thumbnail.jpg</thumbnail>
			<published_on>1385355600000</published_on>
		</content>
	</data>
</response>

Include Page
_Alex.Arriaga
_Alex.Arriaga