Groovy XmlSlurper replace node with given child node value
<p>I'd be grateful for help with the following problem. (I am new to Groovy, and I can't find any specific examples addressing my issue).</p>

<p>Using <code>XmlSlurper</code> I am trying to replace an XML node which has a child with a certain value. For example, I want to transform:</p>

<pre><code>&lt;assets&gt;
    &lt;!--zero to many asset nodes beforehand--&gt;
    &lt;asset&gt;
        &lt;name&gt;MyPackageName&lt;/name&gt;
        &lt;data&gt;
            &lt;stringValue&gt;my string value&lt;/stringValue&gt;
        &lt;/data&gt;
    &lt;/asset&gt;
    &lt;!--zero to many asset nodes afterwards--&gt;
&lt;/assets&gt;
</code></pre>

<p>into: </p>

<pre><code>&lt;assets&gt;
    &lt;!--zero to many asset nodes beforehand--&gt;
    &lt;asset&gt;
        &lt;name&gt;MyPackageName&lt;/name&gt;
        &lt;data/&gt;
    &lt;/asset&gt;
    &lt;!--zero to many asset nodes afterwards--&gt;
&lt;/assets&gt;
</code></pre>

<p>I can't find any examples of code which navigate to find my asset with the name MyPackageName.</p>

<p>My failing attempt is:</p>

<pre><code>    def assets = new XmlSlurper().parseText(deviceXml)
    assets.asset[name.text()=="MyPackageName"].replaceNode{
        asset{
            name("MyPackageName")
            data()
        }
    }
</code></pre>

<p>I get a <code>groovy.lang.MissingPropertyException</code> exception for a missing property for "asset" so clearly my syntax to find my node is wrong.</p>