title: How to add child elements dynamically to SOAP request in SOAPUI using groovy script
body: <p>I have a request which accepts 1..n items to add to basket. default request has one "item" element with some child elements, i want to add N no of items with child element i'm able to add Item parent element using creaeElementNS now i want to add child elements to "item" like following, can someone shed some light on this</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;basket:item&gt;
  &lt;basket:itemId&gt;222&lt;/basket:itemId&gt;
  &lt;basket:itemCode&gt;DEF&lt;/basket:itemCode&gt;
  &lt;basket:item&gt;
  </code></pre>
  
  <p><em>Groovy script</em></p>
  
  <pre class="lang-js prettyprint-override"><code>def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
  def holder = groovyUtils.getXmlHolder( "createBasket#Request" )
  def parentnode = holder.getDomNode( "//basket:createBasketRequest" )
  def basketTotal=   holder.getDomNode( "//basket:itemsTotal" ) 
  def itemsTag = requestDoc.createElementNS(parentnode.getNamespaceURI(), "item")
  parentnode.insertBefore(itemsTag  , basketTotal)
  holder.updateProperty()
  </code></pre>
  
  <p><em>Current Output</em></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;basket:createBasketRequest&gt;
  &lt;basket:item&gt;
      &lt;basket:itemId&gt;111&lt;/basket:itemId&gt;
      &lt;basket:itemCode&gt;ABC&lt;/basket:itemCode&gt;
  &lt;/basket:item&gt;
  &lt;basket:item&gt;
  &lt;/basket:item&gt;
      &lt;basket:itemsTotal&gt;500.00&lt;/basket:itemsTotal&gt;
  &lt;/basket:createBasketRequest&gt;
  </code></pre>
  
  <p><em>Desired Output</em></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;basket:createBasketRequest&gt;
      &lt;basket:item&gt;
          &lt;basket:itemId&gt;111&lt;/basket:itemId&gt;
          &lt;basket:itemCode&gt;ABC&lt;/basket:itemCode&gt;
      &lt;/basket:item&gt;
      &lt;basket:item&gt;
          &lt;basket:itemId&gt;222&lt;/basket:itemId&gt;
          &lt;basket:itemCode&gt;DEF&lt;/basket:itemCode&gt;
      &lt;basket:item&gt;
      &lt;basket:itemsTotal&gt;500.00&lt;/basket:itemsTotal&gt;
  &lt;/basket:createBasketRequest&gt;
  </code></pre>
  
  <p>EDIT: I'm using soapUI and TestCase option, there is a GroovyScript step before add basket request step, groovy script prepares add basket request before actually sending request, for example if my testcase mentions 1 item it should request with default one item so i have no worries to add another Item elements but when my testcase says 2 items i have to create second Items elements(along with child elements) and prepare the add basket request using groovy script step before actually sending add basket request</p>