Indentation of elements but not of comments

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
Posts: 3
Joined: Mon May 19, 2014 1:24 pm

Indentation of elements but not of comments

Post by MikeUnwalla » Mon Jan 27, 2020 9:05 pm

I want to indent the elements in an XML document. Tools>Format and Indent Files lets me do this. To specify the indentation, I can use Options>Preferences>Editor/Format/XML.

Some of the elements have comments at the end of a line. Example:

Code: Select all

     <pattern><!-- This is a comment -->
I want the pattern element to be indented, but I don't want the comment on a new line. (I tried to use Elements Spacing, but I could not make it do what I want.) Is there a simple way to do what I want?

Mike Unwalla

Posts: 2750
Joined: Tue May 17, 2005 4:01 pm

Re: Indentation of elements but not of comments

Post by adrian » Mon Feb 10, 2020 11:39 am


We've discussed this on the Oxygen users list, but I'm also mentioning it here in case anyone else wants something similar.

There is no option in Oxygen to tell the formatter to treat an XML comment differently.
Oxygen formats an element differently depending on its type of content (elements and/or text).
Given your description (that the line breaks before the comment), I can only assume that your "pattern" element contains only elements
(element-only content).

Code: Select all

    <pattern><!-- This is a comment -->
In this case, if you want to force the formatter to keep the XML comment where it is without breaking the line, you can tell it that "pattern"
has "Mixed content" (elements and text). In Editor / Format / XML, go to the Elements spacing > "Mixed content" tab and Add the "pattern" element to the list.

Also note that if there is a space between the start tag and the comment, the Oxygen formatter will consider it's fair to replace the space with a line break.

Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger

Post Reply