ReSharper 2016.3 Help

Coding Assistance in XML

Most of ReSharper's coding assistance features are also supported in XML. You can find the detailed information on these features in the corresponding topics of the Coding Assistance section. In the main topic of the section, you can also find the feature matrix and check what exactly is supported in XML.

In this topic, you can find some examples of using coding assistance features in XML:

Examples of Context Actions

ReSharper provides a set of context actions that target XML code. You can find the full list of these actions in the Code Editing | XML | Context actions page of ReSharper options. If necessary, you can also disable some of the actions using this page.

As soon as a context action becomes available for the current caret position, ReSharper displays the corresponding action indicator /help/img/dotnet/2016.3/ThemedIcon.ContextAction.Screen.[Gray].png to the left of the caret. Sometimes, however, ReSharper provides several contextually available features for the current caret position. In this case, the action indicator corresponding to the action with the highest priority is shown, and all other actions only appear when you expand the action list by clicking on the action indicator or pressing Alt+Enter Context actions have the lowest priority, therefore, they often appear in the bottom of the action list:

Here are some examples of context actions for XML:

Convert text to CData
If your text inside a tag has XML symbols, it needs to be converted to CData in order not to break the structure of the document. Luckily, there is an appropriate context action.

/help/img/dotnet/2016.3/ReSharper_by_Language__XML__Context_Actions__convert_text_01.png

After applying the context action, your text is wrapped with [CDATA[]] and you can now use XML symbols.
/help/img/dotnet/2016.3/ReSharper_by_Language__XML__Context_Actions__convert_text_02.png

Remove tag and promote children
If you restructure your XML document and want to remove a level of nesting, use this context action.

/help/img/dotnet/2016.3/ReSharper_by_Language__XML__Context_Actions__remove_and_promote_01.png

After applying the context action, the buttons tag is removed and all its child tags are promoted one level up.
/help/img/dotnet/2016.3/ReSharper_by_Language__XML__Context_Actions__remove_and_promote_02.png

Collapse empty tag
If a tag doesn't contain any children or text, it can be converted to an empty tag. There is a context action for this purpose as well.

/help/img/dotnet/2016.3/ReSharper_by_Language__XML__Context_Actions__collapse_empty_tag_01.png

After applying the context action, the MiddleName tag is converted to an empty tag.
/help/img/dotnet/2016.3/ReSharper_by_Language__XML__Context_Actions__collapse_empty_tag_02.png

Rearrange code

Rearranging Code Elements is available in XML files. So you can move a tag up or down by pressing Ctrl+Shift+Alt+Up or Ctrl+Shift+Alt+Down. Consider the example below.

/help/img/dotnet/2016.3/Coding_Assistance__Moving_Code_Elements__move_xml_tags_01.PNG

The author tag can be moved down or out of its parent tag, or into some other tag.
/help/img/dotnet/2016.3/Coding_Assistance__Moving_Code_Elements__move_xml_tags_02.PNG

You can also move any attribute within a tag to the left or to the right.

/help/img/dotnet/2016.3/Coding_Assistance__Moving_Code_Elements__move_xml_tags_03.PNG

Place the caret at attribute name and press Ctrl+Shift+Alt+Left or Ctrl+Shift+Alt+Right depending on your goals.
/help/img/dotnet/2016.3/Coding_Assistance__Moving_Code_Elements__move_xml_tags_04.PNG

See Also

Last modified: 3 April 2017