Change XML attribute
org.openrewrite.xml.ChangeTagAttribute
Alters XML attribute value on a specified element.
Recipe source
GitHub, Issue Tracker, Maven Central
This recipe is available under the Apache License Version 2.0.
Options
| Type | Name | Description | Example |
|---|---|---|---|
String | elementName | The name of the element whose attribute's value is to be changed. Interpreted as an XPath expression. | property |
String | attributeName | The name of the attribute whose value is to be changed. | name |
String | newValue | The new value to be used for key specified by attributeName, Set to null if you want to remove the attribute. | newfoo.bar.attribute.value.string |
String | oldValue | Optional. Only change the property value if it matches the configured oldValue. | foo.bar.attribute.value.string |
Boolean | regex | Optional. Default false. If true, oldValue will be interpreted as a Regular Expression, and capture group contents will be available in newValue. |
Used by
This recipe is used as part of the following composite recipes:
- Change cacheManager to use the SimpleCacheManager
- Migrate XJC Bindings to Jakata XML
- Migrate from OptaPlanner to Timefold Solver
- Migrate to Struts 6.0 constants
- Migrate xmlns entries and javax. packages in
ejb-jar.xmlfiles - Migrate xmlns entries and javax. packages in
validation.xmlfiles - Migrate xmlns entries in
**/batch-jobs/*.xmlfiles. - Migrate xmlns entries in
**/validation/*.xmlfiles. - Migrate xmlns entries in
*-jdbc.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
*-jms.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
*.tldfiles. - Migrate xmlns entries in
*.xjbfiles. - Migrate xmlns entries in
*taglib*.xmlfiles for Jakarta Server Faces 3 - Migrate xmlns entries in
application-client.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
application-client.xmlfiles. - Migrate xmlns entries in
application.xmlfiles. - Migrate xmlns entries in
batch.xmlfiles. - Migrate xmlns entries in
beans.xmlfiles for Beans 3.0. - Migrate xmlns entries in
beans.xmlfiles - Migrate xmlns entries in
ejb-jar.xmlfiles. - Migrate xmlns entries in
faces-config.xmlfiles for Jakarta Server Faces 3 - Migrate xmlns entries in
faces-config.xmlfiles - Migrate xmlns entries in
faces-config.xmlfiles - Migrate xmlns entries in
handler.xmlfiles. - Migrate xmlns entries in
orm.xmlfiles - Migrate xmlns entries in
permissions.xmlfiles. - Migrate xmlns entries in
persistence-configuration.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
persistence.xmlfiles - Migrate xmlns entries in
persistence.xmlfiles - Migrate xmlns entries in
plan.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
ra.xmlfiles (Connectors). - Migrate xmlns entries in
resource-deployment-plan.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
taglib.xmlfiles - Migrate xmlns entries in
taglib.xmlfiles - Migrate xmlns entries in
test-web.xmlfiles for Jakarta Server Faces 3 using test interfaces - Migrate xmlns entries in
web-fragment.xmlfiles for Jakarta Server Faces 3 - Migrate xmlns entries in
web-fragment.xmlfiles - Migrate xmlns entries in
web-fragment.xmlfiles - Migrate xmlns entries in
web.xmlfiles for Jakarta Server Faces 3 - Migrate xmlns entries in
web.xmlfiles - Migrate xmlns entries in
web.xmlfiles - Migrate xmlns entries in
weblogic-application.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-ejb-jar.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-pubsub.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-ra.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-rdbms-jar.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-webservices-policy.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-webservices.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-wsee-clientHandlerChain.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic-wsee-standaloneclient.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
weblogic.xmlfiles to WebLogic 14.1.2 - Migrate xmlns entries in
webservices.xmlfiles. - Remove unnecessary
use-authorization-managerfor message security in Spring security 6 - Replace global method security with method security
- Upgrade to Maven model version 4.1.0
Example
Parameters
| Parameter | Value |
|---|---|
| elementName | bean |
| attributeName | id |
| newValue | myBean2.subpackage |
| oldValue | myBean.subpackage |
| regex | null |
- xml
- Diff
Before
<beans>
<bean id='myBean.subpackage.subpackage2'/>
<other id='myBean.subpackage.subpackage2'/>
</beans>
After
<beans>
<bean id='myBean2.subpackage.subpackage2'/>
<other id='myBean.subpackage.subpackage2'/>
</beans>
@@ -2,1 +2,1 @@
<beans>
- <bean id='myBean.subpackage.subpackage2'/>
+ <bean id='myBean2.subpackage.subpackage2'/>
<other id='myBean.subpackage.subpackage2'/>
Usage
This recipe has required configuration parameters. Recipes with required configuration parameters cannot be activated directly (unless you are running them via the Moderne CLI). To activate this recipe you must create a new recipe which fills in the required parameters. In your rewrite.yml create a new recipe with a unique name. For example: com.yourorg.ChangeTagAttributeExample.
Here's how you can define and customize such a recipe within your rewrite.yml:
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangeTagAttributeExample
displayName: Change XML attribute example
recipeList:
- org.openrewrite.xml.ChangeTagAttribute:
elementName: property
attributeName: name
newValue: newfoo.bar.attribute.value.string
oldValue: foo.bar.attribute.value.string
Now that com.yourorg.ChangeTagAttributeExample has been defined, activate it in your build file:
- Gradle
- Maven
- Moderne CLI
- Add the following to your
build.gradlefile:
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("com.yourorg.ChangeTagAttributeExample")
setExportDatatables(true)
}
repositories {
mavenCentral()
}
- Run
gradle rewriteRunto run the recipe.
- Add the following to your
pom.xmlfile:
<project>
<build>
<plugins>
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.22.1</version>
<configuration>
<exportDatatables>true</exportDatatables>
<activeRecipes>
<recipe>com.yourorg.ChangeTagAttributeExample</recipe>
</activeRecipes>
</configuration>
</plugin>
</plugins>
</build>
</project>
- Run
mvn rewrite:runto run the recipe.
You will need to have configured the Moderne CLI on your machine before you can run the following command.
mod run . --recipe ChangeTagAttribute --recipe-option "elementName=property" --recipe-option "attributeName=name" --recipe-option "newValue=newfoo.bar.attribute.value.string" --recipe-option "oldValue=foo.bar.attribute.value.string"
If the recipe is not available locally, then you can install it using:
mod config recipes jar install org.openrewrite:rewrite-xml:8.64.0
See how this recipe works across multiple open-source repositories
Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.
Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.
Data Tables
- SourcesFileResults
- SourcesFileErrors
- RecipeRunStats
Source files that had results
org.openrewrite.table.SourcesFileResults
Source files that were modified by the recipe run.
| Column Name | Description |
|---|---|
| Source path before the run | The source path of the file before the run. null when a source file was created during the run. |
| Source path after the run | A recipe may modify the source path. This is the path after the run. null when a source file was deleted during the run. |
| Parent of the recipe that made changes | In a hierarchical recipe, the parent of the recipe that made a change. Empty if this is the root of a hierarchy or if the recipe is not hierarchical at all. |
| Recipe that made changes | The specific recipe that made a change. |
| Estimated time saving | An estimated effort that a developer to fix manually instead of using this recipe, in unit of seconds. |
| Cycle | The recipe cycle in which the change was made. |
Source files that errored on a recipe
org.openrewrite.table.SourcesFileErrors
The details of all errors produced by a recipe run.
| Column Name | Description |
|---|---|
| Source path | The file that failed to parse. |
| Recipe that made changes | The specific recipe that made a change. |
| Stack trace | The stack trace of the failure. |
Recipe performance
org.openrewrite.table.RecipeRunStats
Statistics used in analyzing the performance of recipes.
| Column Name | Description |
|---|---|
| The recipe | The recipe whose stats are being measured both individually and cumulatively. |
| Source file count | The number of source files the recipe ran over. |
| Source file changed count | The number of source files which were changed in the recipe run. Includes files created, deleted, and edited. |
| Cumulative scanning time (ns) | The total time spent across the scanning phase of this recipe. |
| Max scanning time (ns) | The max time scanning any one source file. |
| Cumulative edit time (ns) | The total time spent across the editing phase of this recipe. |
| Max edit time (ns) | The max time editing any one source file. |