Modifying ear plugin generated application.xml using withXml{ }

I want to be able to modify the element/node value based on the value using webXml{ }.

Here is a sample of the xml I am working with:

fileName.war specifiedContextRoot fileName2.war specifiedContextRoot

Based on the different fileName values for “web-uri”, I need to change the value of the “context-root” - how can I do this using withXml { }? The xml file is automatically generated through gradle

thanks for any help in advance.

Could you please properly format your XML example code? It’s hard to propose pseudo code if you don’t know what your XML structure looks like.

Sorry, didn’t realize it didn’t take the entire file, here is what the generated application.xml looks like:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
  <display-name>TestApp</display-name>
  <module>
    <web>
      <web-uri>TestApp.war</web-uri>
      <context-root>customized/text</context-root>
    </web>
  </module>
  <module>
    <web>
      <web-uri>TestApp.war</web-uri>
      <context-root>customized/text</context-root>
    </web>
  </module>
</application>

You are basically navigating a hierarchy of groovy.util.Nodes. when using withXml. You can find out how to work with XML processing in Groovy in their documentation.