Predefined Refactoring Operations

The XML Refactoring tool includes a variety of predefined operations that can be used for common refactoring tasks. They are grouped by category in the Refactoring operations wizard page. You can also access the operations from the Refactoring submenu in the contextual menu of Author or Text mode. The operations are also grouped by category in this submenu (Attributes, Elements, and Fragments). When selecting the operations from the contextual menu, Oxygen XML Editor considers the editing context to get the names and namespaces of the current element or attribute, and uses this information to preconfigure some of the parameter values for the selected refactoring operation.

The following predefined operations are available:

Refactoring Operations for Attributes

Add/Change attribute
Use this operation to change the value of an attribute or insert a new one. To perform this operation, specify the following parameters:
  • The parent Element of the attribute to be changed, in the form of a local name from any namespace, a local name with a namespace prefix, or an XPath expression.
  • The Local name, Namespace, and Value of the affected attribute.
  • One of the following choices for the Operation mode in the Options section:
    • Add the attribute in the parent elements where it is missing
    • Change the value in the parent elements where the atrribute already exists
    • Both
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Delete attribute
Use this operation to remove one or more attributes. To perform this operation, specify the following parameters:
  • The parent Element of the attribute to be deleted, in the form of a local name from any namespace, a local name with a namespace prefix, or an XPath expression.
  • The name of the Attribute to be deleted.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Rename attribute
Use this operation to rename an attribute. Specify the following parameters in the Rename attribute dialog box:
  • The parent Element of the attribute to be renamed, in the form of a local name from any namespace, a local name with a namespace prefix, or an XPath expression.
  • The name of the Attribute to be renamed.
  • New local name of the attribute.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Replace in attribute value
Use this operation to search for a text fragment inside an attribute value and change the fragment to a new value. To perform this operation, specify the following parameters:
  • The parent Element of the attribute to be modified, in the form of a local name from any namespace, a local name with a namespace prefix, or an XPath expression.
  • The name of the Attribute to be modified.
  • The text fragments to Find. You can use Perl-like regular expressions when specifying the text to find.
  • The text fragment to Replace with. This parameter can bind regular expression capturing groups ($1, $2, etc.) from the find pattern.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.

Refactoring Operations for Elements

Delete element
Use this operation to delete elements. To perform this operation, specify the following parameter:
  • The target Element to be deleted, in the form of a local name from any namespace, a local name with a namespace prefix, or an XPath expression.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Delete element content
Use this operation to delete the content of elements. To perform this operation, specify the following parameter:
  • The target Element in which its content is to be deleted, in the form of a local name from any namespace, a local name with a namespace prefix, or an XPath expression.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Insert element
Use this operation to insert new elements. To perform this operation, specify the following parameters:
  • The Local name of the element to be inserted.
  • The Namespace of the element to be inserted.
  • The XPath location of an existing element where the new element will be inserted, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
  • The Position, in relation to the specified existing element, where the new element will be inserted. The possible selections in the drop-down menu are: After, Before, First child, or Last child.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Rename element
Use this operation to rename elements. To perform this operation, specify the following parameters:
  • The Target elements (XPath) to be renamed, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
  • The New local name of the element.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Unwrap element
Use this operation to remove the surrounding tags of elements, while keeping the content unchanged. To perform this operation, specify the following parameters:
  • The Target elements (XPath) for which its surrounding tags will be removed, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Wrap element
Use this operation to surround elements with element tags. To perform this operation, specify the following parameters:
  • The Target elements (XPath) to be surrounded with tags, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
  • The Local name of the Wrapper element.
  • The Namespace of the Wrapper element.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Wrap element content
Use this operation to surround the content of elements with element tags. To perform this operation, specify the following parameters:
  • The Target elements (XPath) to surround its content with tags, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
  • The Local name of the Wrapper element in which its content will be wrapped.
  • The Namespace of the Wrapper element in which its content will be wrapped.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.

Refactoring Operations for Fragments

Insert XML fragment
Use this operation to insert an XML fragment. To perform this operation, specify the following parameters:
  • The XML Fragment to be inserted.
  • The XPath location of an existing element where the fragment will be inserted, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
  • The Position, in relation to the specified existing element, where the fragment will be inserted. The possible selections in the drop-down menu are: After, Before, First child, or Last child.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Replace element content with XML fragment
Use this operation to replace the content of elements with an XML fragment. To perform this operation, specify the following parameters:
  • The Target elements (XPath) for which its content will be replaced, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
  • The XML Fragment with which to replace the content of the target element.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.
Replace element with XML fragment
Use this operation to replace elements with an XML fragment. To perform this operation, specify the following parameters:
  • The Target elements (XPath) to be replaced, in the form of a local name from any namespace, a local name with a namespace prefix, or other XPath expressions.
  • The XML Fragment with which to replace the target element.
Tip: Use the link provided in the lower part of the wizard to open the XML / XSLT-FO-XQuery / XPath preferences page where you can configure XPath options and declare namespace prefixes.

Additional Notes

Note: There are some operations that allows <ANY> for the local name and namespace parameters. This value can be used to select an element or attribute regardless of its local name or namespace. Also, the <NO_NAMESPACE> value can be used to select nodes that do not belong to a namespace.
Note: Some operations have parameters that accept XPath expressions to match elements or attributes. In these XPath expressions you can only use the prefixes declared in the Options > Preferences > XML > XSLT-FO-XQUERY > XPath page. This preferences page can be easily opened by clicking the link in the note (Each prefix used in an XPath expression must be declared in the Default prefix-namespace mappings section) at the bottom of the Configure Operation Parameters wizard page.