title: Groovy Xml Parsing with namespaces
body: <p>I've been trying to do some xml modifications with groovy's XML Slurper. </p>
  
  <p>Basically, i'm going through the xml and looking for tags or attributes that have ? as the value and then replacing it with some value. </p>
  
  <p>I've got it working for xml that doesn't have namespaces but once I include them things get wonky. For example, this:</p>
  
  <pre><code>   String foo = "&lt;xs:test xmlns:xs="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:foo="http://myschema/xmlschema" name='?'&gt;
          &lt;foo:tag1&gt;?&lt;/foo:tag1&gt;
          &lt;foo:tag2&gt;?&lt;/foo:tag2&gt;
      &lt;/xs:test&gt;";
  </code></pre>
  
  <p>produces: </p>
  
  <p><code>&lt;Envelope/&gt;</code></p>
  
  <p>Here's the groovy code I'm using. This does appear to work when I am not using a namespace:</p>
  
  <pre><code> public def populateRequest(xmlString, params) {
  
       def slurper = new XmlSlurper().parseText(xmlString)
       //replace all tags with ?
       def tagsToReplace = slurper.depthFirst().findAll{ foundTag -&gt;
          foundTag.text() == "?"
       }.each { foundTag -&gt;
          foundTag.text = {webServiceOperation.parameters[foundTag.name()]}
         foundTag.replaceNode{
              "${foundTag.name()}"(webServiceOperation.parameters[foundTag.name()])
          }
        }
        //replace all attributes with ?
        def attributesToReplace = slurper.list().each{
            it.attributes().each{ attributes -&gt;
            if(attributes.value == '?')
            {
              attributes.value = webServiceOperation.parameters[attributes.key]
            }
          }
        }
  
        new StreamingMarkupBuilder().bind { mkp.yield slurper }.toString()
     }
  </code></pre>