title: How do you add an attribute and node value when creating xml in groovy
body: <p>I'm using to groovy to create a dynamic XML document where each node can contain a value, attributes, or both. </p>
  
  <p>For example</p>
  
  <pre><code>&lt;root&gt;
    &lt;a id="123"&gt; someValue &lt;/a&gt;
  &lt;root&gt;
  </code></pre>
  
  <p>I can't seem to find an example of where a node is created with both a value and a set of attributes. </p>
  
  <p>Here's the line of code that creates a node (inside other code that creates the XML document and root element)</p>
  
  <pre><code>// node is a map, as is node.attributes
  "${node.node_name}"(node.attributes.each { k, v -&gt; "${k}:${v}"})
  </code></pre>
  
  <p>creates the following:</p>
  
  <pre><code>&lt;a id=123 /&gt;
  </code></pre>
  
  <p>whereas:</p>
  
  <pre><code>"${node.node_name}""${node.value}"
  </code></pre>
  
  <p>creates:</p>
  
  <pre><code>&lt;a&gt;someValue &lt;a&gt;
  </code></pre>
  
  <p>What code would create a node with both the attribute and value set, looking like this:</p>
  
  <pre><code>&lt;a id=123&gt; someValue &lt;/a&gt;
  </code></pre>
  
  <p>Any help is appreciated.</p>