title: Optimizing XML response of web service
body: <p>In performance tests of our web service we found out that the <strong>traffic</strong> generated by the response exceeded our expectations a lot. We are querying the database and loading lists consisting of rows and columns. </p>
  
  <p>The type of the column is <strong>AnyType</strong> so the in the response there needs to be a type information. Therefor the web service engine (Axis2 or JAXWS) adds a lot of <strong>namespace information multiple times</strong>. See the following example response:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;soapenv:Body&gt;
        &lt;ns3:loadListResponse xmlns:ns3="http://example.com/test/service-types-1.0" 
        xmlns:ns2="http://example.com/lists/lists-types-1.0" &gt;
           &lt;ns3:value&gt;
              &lt;ns2:row&gt;
                 &lt;ns2:column xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;12345&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;XYZ&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt;
                 &lt;ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;ABC&lt;/ns2:column&gt;
              &lt;/ns2:row&gt;
              &lt;ns2:row&gt;
                 &lt;ns2:column xsi:type="xs:int" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;32345&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;OPC&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/&gt;
                 &lt;ns2:column xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;QWE&lt;/ns2:column&gt;
              &lt;/ns2:row&gt;
               .
               .
               .
           &lt;/ns3:value&gt;
        &lt;/ns3:loadListResponse&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>I would like to optimize this XML response by adding the required namespaces at the top and removing them from every column (usually there are about 30 columns per line). The result should look like this:</p>
  
  <pre><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
     &lt;soapenv:Body&gt;
        &lt;ns3:loadListResponse xmlns:ns3="http://example.com/test/service-types-1.0" 
        xmlns:ns2="http://example.com/lists/lists-types-1.0" &gt;
           &lt;ns3:value&gt;
              &lt;ns2:row&gt;
                 &lt;ns2:column xsi:type="xs:int" &gt;12345&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:type="xs:string" &gt;XYZ&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:nil="true" /&gt;
                 &lt;ns2:column xsi:type="xs:string" &gt;ABC&lt;/ns2:column&gt;
              &lt;/ns2:row&gt;
              &lt;ns2:row&gt;
                 &lt;ns2:column xsi:type="xs:int" &gt;32345&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:type="xs:string" &gt;OPC&lt;/ns2:column&gt;
                 &lt;ns2:column xsi:nil="true" /&gt;
                 &lt;ns2:column xsi:type="xs:string" &gt;QWE&lt;/ns2:column&gt;
              &lt;/ns2:row&gt;
               .
               .
               .
           &lt;/ns3:value&gt;
        &lt;/ns3:loadListResponse&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>How would you do something like that?</p>
  
  <p>Is there a way to tell Axis2 or JAXWS to do so?</p>
  
  <p>Or do I need to manipulate the generated XML manually?</p>