Lately, the frameworks I’ve been using have been configured with XML files – ColdSpring, ModelGlue, and ValidateThis. If you’re coding XML, and use either the basic XML editor in Eclipse or the Aptana XML editor in ColdFusion Builder, you’re potentially missing out on some slick code completion offered by another Eclipse plugin… the WebTools project, which contains my free XML Editor of choice.
Use the normal “Help -- Install new software” process in Eclipse, using http://download.eclipse.org/webtools/updates/ as the update site.
What’s it get me?
The WTP XML editor has two must-have features:
- It “learns” your XML and begins providing code assist after it knows what elements are in your files
- If your XML file contains a schema declaration, it’ll provide very rich code assist for both elements and attributes
This is me editing a ModelGlue xml config file. Note that the file has this attribute on the modelglue element: xsi:noNamespaceSchemaLocation="http://www.model-glue.com/schema/gesture/ModelGlue.xsd"
Yes, that’s a valid URL.
This means that if your framework of choice makes an XSD schema available, then you can add the appropriate URI to your XML file and voila, the editor will start providing code assist.
One other small-but-useful feature is automatic element shorthand. Let me explain:
Imagine you type this: <param name=”regex” value=”(?i)password”></param>
Or, rather, imagine the editor auto-closed that tag. Now, if you put your cursor right after password” and before the closing angle bracket, and enter the backslash, the editor will automatically remove the closing element. Small, but the little things in life matter.
How do I edit XML files with a CFM Extension?
A best practice for the XML files is to suffix them with a .cfm extension, i.e. ModelGlue.xml.cfm if those files are web-accessible. This way, you can put an Application.cfm in that directory, with a CFABORT, and those xml config files are no longer readable (assuming you don’t lock them down with your webserver). The problem here is that once they have a .cfm extension, they don’t play nicely with the XML editor.
Fortunately, this is an easy fix.
- Open the Eclipse preferences
- Filter on “content type”
- Scroll down, expand “text”, then go to “XML“
- In the bottom pane, click “Add” and then type “.cfm”. Click OK till finished.
Here’s what that looks like:
That’s step 1. Step 2 is actually opening a .cfm file in the WTP XML Editor.
- Right click on your .xml.cfm file
- Select “Open With”
- If '”XML Editor” is an option, choose it. Otherwise, click the “Other” and scroll down till you see the XML editor. It’ll be at the bottom. Note this is not the “Aptana XML Editor”
That dialog looks like this:
This is a one time thing! Once you open a particular .xml.cfm file in the XML editor, it’ll always open in that editor until you instruct it otherwise.
How does Eclipse know that your .xml.cfm is an XML content type?
You may have a .xml.cfm file that, when you open with the xml editor via right click – open with, continues to give you the “invalid content type” popup. This is most likely because the file does not have the xml declaration at the top. For example, if you have a Coldspring beans.xml.cfm file and it starts with <beans>, you’ll probably get this error. The fix is to add <?xml version="1.0" encoding="UTF-8"?> to the top of your file.
If you want code assist on your XML files, both .xml and .xml.cfm, then take 5 minutes to install the WTP XML Editor. Give it a go, and see if it’s right for you.