title: Convert Java Object to soap XML
body: <p>Say i have object of employee </p>
  
  <pre><code>Employee employee = new Employee();
  employeee.setId(1);
  employee.setName("stack");
  </code></pre>
  
  <p>I want to convert this in he below format </p>
  
  <p>this is below xml fomat i want</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;soapenv:Envelope xmlns:soapenv="http:/someurl" xmlns:bas="http://someurl" xmlns:req="http://someurl" xmlns:sch="http://someurl"&gt;
     &lt;soapenv:Body&gt;
  
     &lt;ns1:employeeReturn xmlns:ns1="someurl"&gt;
           &lt;ns2:result xmlns:ns2="someurl"&gt;
              &lt;ns3:resultCode xmlns:ns3="someurl"&gt;00000000&lt;/ns3:resultCode&gt;
              &lt;ns4:resultMessage xmlns:ns4="someurl"&gt;Success&lt;/ns4:resultMessage&gt;
           &lt;/ns2:result&gt;
           &lt;ns5:resultList xmlns:ns5="http://someurl"&gt;
              &lt;ns1:item&gt;
                 &lt;ns6:resultCode xmlns:ns6="http://someurl"&gt;00000000&lt;/ns6:resultCode&gt;
              &lt;/ns1:item&gt;
           &lt;/ns5:resultList&gt;
           &lt;ns7:subResponseInfos xmlns:ns7="http://someurl"&gt;
              &lt;ns1:item&gt;
                 &lt;ns8:effectiveEndTime   xmlns:ns8="http://someurl"&gt;20361231170000&lt;/ns8:effectiveEndTime&gt;
                &lt;/ns1:item&gt;
                &lt;/ns1:employeeReturn &gt;
                   &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  
  <p>I Have tried to create soap message as follows</p>
  
  <pre><code>SOAPMessage soapMessage = messageFactory.createMessage();
  
          SOAPPart soapPart = soapMessage.getSOAPPart();
          SOAPEnvelope envelope = soapPart.getEnvelope();
          SOAPBody body = envelope.getBody();
  
          envelope.addNamespaceDeclaration("xsi", "http://url");
  
          SOAPBodyElement element0 = body.addBodyElement(
                  envelope.createName("employeereturn", "ns1", "http://url"));
  
  
          SOAPElement element1 = element0.addChildElement(
                  body.addBodyElement(envelope.createName("result", "ns2", "http://url")));
  
          SOAPElement element2 = element1.addChildElement(body.addBodyElement(envelope.createName("resultCode", "ns3", "http://url"))).addTextNode("00000");
  
          element1.addChildElement(body.addBodyElement(envelope.createName("resultMessage", "ns4", "http://url"))).addTextNode("success");
  
  
          SOAPElement element3 = element0.addChildElement(
                      body.addBodyElement(envelope.createName("resultList", "ns5", "http://url")));
  </code></pre>
  
  <p>but as your employee bject goes bigger and has some nested objects it will be difficult to maintain the code</p>