Eclipse XML SQL Format Tip

1. Problem Description
In some XML files we have tons of SQL sentences, like hibernate.hbm.xml, once you execute the CTRL+SHIFT+F to format the content, you might mess it up! 
2. Solution
Wrap the formatted SQL with the CDATA tag, then Eclipse would not touch the SQL's format.
3. Example
<sql-query name="getCustomerInfo">
	<![CDATA[ 
	SELECT baseT.customer_id    AS customer_id, 
       phone, 
       currency, 
       account_type, 
       active, 
       customer_type, 
       follow_percentages, 
       ( Sum(IF(cust_trans_id IS NULL, 0, IF(accnt_trans_type = 'Credit', 0 - Round(amount, 2), 
                                          IF(accnt_trans_type = 'Debit', Round(amount, 2), 0)))) ) AS balance 
	FROM   (SELECT customerT.customer_id, 
	               customerT.phone, 
	               customerT.credit_limit, 
	               customerT.currency, 
	               customerT.account_type, 
	               customerT.active, 
	               customerT.customer_type, 
	               CONVERT(Ifnull(customerT.follow_percentages, '') USING utf8) AS 
	               follow_percentages 
	        FROM   (SELECT customer.customer_id, 
	        ...
	]]>
</sql-query>

4. Cons
Once you used the editor form UI to edit, rather than write the XML manually, the tag will disappear immediately.

좋은 웹페이지 즐겨찾기