<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>beer planet &#187; auto format</title>
	<atom:link href="http://beerpla.net/tag/auto-format/feed/" rel="self" type="application/rss+xml" />
	<link>http://beerpla.net</link>
	<description>where things have nothing to do with beer - tutorials, tips, how-tos, thoughts, hacks, and other techy nonsense</description>
	<lastBuildDate>Sun, 08 Aug 2010 23:59:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://beerpla.net/?pushpress=hub'/>
		<item>
		<title>[Android] Auto Formatting Android XML Files With Eclipse</title>
		<link>http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/</link>
		<comments>http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 02:44:54 +0000</pubDate>
		<dc:creator>Artem Russakovskii</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[auto format]]></category>
		<category><![CDATA[autoformat]]></category>
		<category><![CDATA[automatic]]></category>
		<category><![CDATA[clean up]]></category>
		<category><![CDATA[cleanup]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[indentation]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[xml]]></category>
		<guid isPermaLink="false">http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/</guid>
		<description><![CDATA[<p><img style="margin: 0px 10px 10px 0px; display: inline" title="image" alt="image" align="left" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb.png" width="150" height="109" /> In this article I will describe the problem I&#039;ve had with Eclipse&#039;s handling of XML file formatting as well as the best way to fix it.</p>
<p>&#160;</p>
<p>I use Eclipse to do my Android development for a few reasons:</p>
<ul>
<li>it&#039;s the only IDE fully supported by the Android dev team </li>
<li>it has a visual Layout/Resources builder that transforms XML files into corresponding visual representations </li>
<li>it&#039;s free and open source </li>
<li>I&#039;ve been using Eclipse for many years and am very familiar with it </li>
</ul>
<p><div class="note"><div class="noteclassic">In order to use the visual features in Eclipse when developing</div></div>...<div class=clear></div> <a href="http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/" class="read_more"><div class=excerpt-end>Read the rest of this article &#187;</div></a></p>]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 0px 10px 10px 0px; display: inline" title="image" alt="image" align="left" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb.png" width="150" height="109" /> In this article I will describe the problem I&#039;ve had with Eclipse&#039;s handling of XML file formatting as well as the best way to fix it.</p>
<p>&#160;</p>
<p>I use Eclipse to do my Android development for a few reasons:</p>
<ul>
<li>it&#039;s the only IDE fully supported by the Android dev team </li>
<li>it has a visual Layout/Resources builder that transforms XML files into corresponding visual representations </li>
<li>it&#039;s free and open source </li>
<li>I&#039;ve been using Eclipse for many years and am very familiar with it </li>
</ul>
<p><div class="note"><div class="noteclassic">In order to use the visual features in Eclipse when developing for Android, you need to install <a href="http://developer.android.com/sdk/eclipse-adt.html" rel="nofollow">the ADT plugin</a> provided by Google</div></div></p>
<h2>The Problem</h2>
<p>However, one thing about Eclipse Android development has bothered me for a while &#8211; and that is XML formatting by the visual tools. See, if you open an XML file in Eclipse and use the Layout/Resources tab (which functions as either a visual UI builder or a visual frontend to resource management), Eclipse creates the XML representation of what you&#039;re building and dumps it into the file you&#039;re editing. The problem is, this XML is not formatted in any way &#8211; Eclipse just writes it in a single line, which looks absolutely horrible and is essentially unusable.</p>
<p>For example, I had this beautifully formatted XML file with a sample Android menu. After using the Layout tab to add another item, I ended up with an single ugly unindented line for it.</p>
<p><a href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_3.png" class="lightview" rel="gallery[1215]" title="image"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_3.png" width="700" height="189" /></a> </p>
<h2>The Solution</h2>
<p>Here&#039;s how to solve this in an almost fully automated fashion, using formatting rules that I think result in the most readable file. There is no need for external tools &#8211; Eclipse provides everything needed.</p>
<ul>
<li>open up Window-&gt;Preferences-&gt;XML-&gt;XML Files-&gt;Editor     <br /><a href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_4.png" class="lightview" rel="gallery[1215]" title="image"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_4.png" width="636" height="667" /></a> </li>
<li>check the &quot;Split multiple attributes each on a new line&quot; and adjust other options according to your liking (such as Indent using spaces and Indentation size)</li>
<li>press OK to save the options</li>
<li>all you have to do now is press Ctrl-Shift-F or select Source-&gt;Format</li>
</ul>
<p>Let&#039;s see what this does to the XML I showed above:</p>
<p><a href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_5.png" class="lightview" rel="gallery[1215]" title="image"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_5.png" width="573" height="333" /></a> It&#039;s a beauty, isn&#039;t it? Eclipse&#039;s Auto Format is one of its best features (yes, you can apply it to your Android Java code too as well as pretty much any other document format).</p>
<h2>Bonus &#8211; XML Cleanup</h2>
<p>As an added bonus, Eclipse also offers a Cleanup XML option, which can do the following:</p>
<ul>
<li>compress empty element tags</li>
<li>insert required attributes</li>
<li>insert missing tags</li>
<li>quote attribute values</li>
<li>format source (as above)</li>
<li>convert line delimiters to Windows, UNIX, or Mac</li>
</ul>
<p>You can access the Cleanup option via Source-&gt;Cleanup</p>
<p><a href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_6.png" class="lightview" rel="gallery[1215]" title="image"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_6.png" width="225" height="247" /></a> Running Cleanup on my already pretty clean XML file turned the last &lt;item&gt; into this:</p>
<p><a href="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_7.png" class="lightview" rel="gallery[1215]" title="image"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="image" alt="image" src="http://beerpla.net/wp-content/uploads/AndroidAutoFormattingAndroidXMLFilesWith_14588/image_thumb_7.png" width="554" height="104" /></a> The first option compressed the &lt;item&gt;&lt;/item&gt; declaration to simply &lt;item /&gt;. Neat, isn&#039;t it?</p>
<h2>Final Words</h2>
<p><strong>+</strong> Clean is good.</p>
<p><strong>+</strong> Uniform is good.</p>
<p><strong>+</strong> Use Ctrl-Shift-F and make it a habit.</p>
<p><strong>+</strong> Create a keyboard shortcut to the Cleanup function by going to Window-&gt;Preferences-&gt;General-&gt;Keys and use it instead of Ctrl-Shift-F (since it already formats as part of the Cleanup).</p>
<p><strong>?</strong> I&#039;d like to know if there is a way to apply auto formatting upon save, automatically. Do you?</p>
<div class="shr-bookmarks shr-bookmarks-expand">
<ul class="socials">
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse+-+http://bit.ly/cNm6Ld&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;t=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;t=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/&amp;title=%5BAndroid%5D+Auto+Formatting+Android+XML+Files+With+Eclipse" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-mail">
			<a href="mailto:?subject=%22%5BAndroid%5D%20Auto%20Formatting%20Android%20XML%20Files%20With%20Eclipse%22&amp;body=Link: http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/ (sent via shareaholic)%0D%0A%0D%0A----%0D%0A %20In%20this%20article%20I%20will%20describe%20the%20problem%20I%27ve%20had%20with%20Eclipse%27s%20handling%20of%20XML%20file%20formatting%20as%20well%20as%20the%20best%20way%20to%20fix%20it.%20%20%26%23160%3B%20%20I%20use%20Eclipse%20to%20do%20my%20Android%20development%20for%20a%20few%20reasons%3A%20%20%20%20%20it%27s%20the%20only%20IDE%20fully%20supported%20by%20the%20Android%20dev%20team%20%20%20%20%20it%20has%20a%20visual%20Layout%2FReso" rel="nofollow" class="external" title="Email this to a friend?">Email this to a friend?</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
Similar Posts:<ul><li><a href="http://beerpla.net/2008/04/09/some-useful-vim-commands-my-vim-cheatsheet/" rel="bookmark" title="April 9, 2008">Some Useful vim Commands &#8211; My vim Cheatsheet</a></li>
<li><a href="http://beerpla.net/2009/10/15/installing-the-android-plugin-for-eclipse/" rel="bookmark" title="October 15, 2009">Installing The Android Plugin For Eclipse</a></li>
<li><a href="http://beerpla.net/2010/01/18/wordpress-developers-how-do-you-make-a-living-poll-discussion/" rel="bookmark" title="January 18, 2010">WordPress Developers &#8211; How Do You Make A Living [Poll + Discussion]?</a></li>
<li><a href="http://beerpla.net/2008/12/22/mastering-the-linux-shell-bash-shortcuts-explained/" rel="bookmark" title="December 22, 2008">Mastering The Linux Shell &#8211; Bash Shortcuts Explained (Now With Cheat Sheets)</a></li>
<li><a href="http://beerpla.net/2009/04/11/essential-firefox-extensions-plugins-add-ons-and-tips-a-comprehensive-guide-part-1-tips/" rel="bookmark" title="April 11, 2009">Essential Firefox Extensions (Plugins, Add-Ons) And Tips &ndash; A Comprehensive Guide :: Part 1 :: Tips</a></li>
</ul><!-- Similar Posts took 13.390 ms --><p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://beerpla.net/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://beerpla.net/2009/11/04/android-auto-formatting-android-xml-files-with-eclipse/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
