IntelliJ IDEA 2018.2 Help

Replace Tag With Attribute

The Replace Tag with Attribute refactoring allows you to replace sub-tags definitions on a set of XMLs tag with equivalent attributes. If this refactoring is invoked, all tags matching the selected tag's name on tags with the selected parent tag name may be removed, and equivalent attributes created. This bulk transformation of sub-tags to attributes is useful as XML schemas evolve.

Converting a tag into an attribute

Pressing Preview opens the Refactoring preview window displaying all found usages of the tags to be replaced. In this window you can exclude/include usages you want to refactor.

Pressing Show XSLT... opens the XSLT preview window displaying an small fragment of XSLT equivalent to the refactoring requested. This fragment can be used by XSLT processors to perform the requested refactoring on files external to your IntelliJ IDEA project.

The Refactoring preview window may appear anyway, if the files to be affected are read-only.

  1. In the editor, place the cursor within the tag to be converted.

  2. Select Refactor | XML Refactorings | Replace Tag with Attribute from the main or the context menu.

    1_tagToAttribute.PNG

  3. Determine the name of the attributes to replace the selected tags.

  4. Determine the scope of the replacement. All tags matching name of the tag selected on the parent tag selected will be replaced, if they are in the selected scope. Scopes available include the current file, the entire project, or a specified directory or module. Directory scopes can either include sub-directories, or not, based on whether the Recursively checkbox is selected. If the Limit to files with DTD:... checkbox is selected, the scope will be limited to those files with the same DOCTYPE as the current file.

  5. Press Preview button to make IntelliJ IDEA to search for usages of the selected tag Find window.

  6. Click OK to continue. If you do not select the Preview option, all usages will be changed immediately.

Last modified: 20 November 2018