2/10/2007

Comment out xml file fragments in java IDE

It's easy to comment out and uncomment lines of Java code in any Java IDE, using shortcut keys like Ctrl-/ (in Eclipse), or Ctrl-Shift-T (in NetBeans). But I haven't found such features for XML commenting. I have to always manually add <!-- and --> even when editing those XML files inside Eclipse or NetBeans.

Why is it missing in major Java IDEs? Nowadays almost all Java projects have some XML files, like ant build files, deployment descriptors, etc. And both NetBeans and Eclipse have nice XML editing features, including syntax highlighting, element and attribute auto-completion, and element tree view. All these seem to suggest Java IDEs are serious in supporting XML development. One would think commenting/uncommenting is one of the basic requirements. Why can't I select some lines, press Ctrl-/ or Ctrl-Shift-T to comment out them?

Maybe one reason is that XML doesn't allow nested comments. So if my selection already contains XML comments, I can't add an outer comment. But even in this case, the IDE can either issue a waring, or add 2 smaller comments, one before the existing comment and the other after.

11 comments:

Anonymous said...

IDEA comments/uncomments XML for you with CTRL-/ (toggle line-by-line comments) and CTRL-SHIFT-/ (toggle block comments). In fact ANY file type can have associated line and block comment markers that will be applied appropriately whenever CTRL-/ or CTRL-SHIFT-/ is pressed. I often edit Python, SQL and C++ in IDEA so this is very useful.

With nested comments, the quickest way to deal with them is to select the whole area you want to comment (eg with the fantastic CTRL-W) then press CTRL-SHIFT-/ twice. The first strips existing comments, the second press will block comment the whole area. You do lose the original comment region with this approach though.

Pete Carapetyan said...

With the WTP plugins installed, using the xml editor they provide, Eclipse does this easily and I use all the time.

It's the only thing I use the WTP plugin for, actually, but that's more about my lack of skills than the plugin.

gaferoz said...

Perhaps you haven't tried selecting the block of lines and them clicking the right button, then 'Source' and then 'Add Block Comment'...

Mihai Rus said...

Eclipse IDE CTRL + SHIFT + C - toggle comments in xml files

Cindy Dy said...

You made some good points there. I did a search on the matter and found the majority of people will consent with your blog.

Haidee
www.gofastek.com

andrea chiu said...

I understand that every person has the passion in any aspects or things. If you love something and it came in front of you it completes your day and your mood turns into something you won't expected. I love your work and I want to read more about it. Visit my site if you have time . Thank you.

triciajoy.com

www.triciajoy.com

lee woo said...

Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.


ufgop.org
ufgop.org

Steve Smith said...

Great and Useful Article.

Online Java Training

Java Online Training India

Java Online Course

Java EE course

Java EE training

Best Recommended books for Spring framework

Java Interview Questions








Java Course in Chennai

Java Online Training India

Geetha Devi said...

Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more .java training in chennai

Sherlin Jones said...

The biggest change in Selenium recently has been the inclusion of the WebDriver API. Driving a

browser natively as a user would either locally or on a remote machine using the Selenium Server it

marks a leap forward in terms of browser automation.

Selenium WebDriver fits in the same role as RC did, and has incorporated the original 1.x bindings.

It refers to both the language bindings and the implementations of the individual browser controlling

code. This is commonly referred to as just "WebDriver" or sometimes as Selenium 2.
Selenium Training Institute in Chennai

Selenium Training in Chennai
Selenium Training with placement assistance in Chennai

Jones Sathya said...

When we speak of Selenium, we are actually talking about both its flavours: Selenium WebDriver and Selenium IDE. Both automate browsers in support of web application testing. WebDriver is typically used to create browser-based regression tests, whereas Selenium IDE is most advantageous in creating unit tests, exploratory tests and one-off bug reproduction scripts. There is no need to make further distinctions between the two, however, when discussing Selenium’s advantages and disadvantages.
Selenium Training in Chennai|Selenium Trianing in Velachery