title: Web service returning multiple values in a single row delimited by tags
body: <p>I need to build a web service that returns multiple rows from database and each row should containt several fields delimited by tags. I created this ws using Netbeans and it is running on a glassfish server. I only managed to return tagged rows containing a string made by concatenated values (fields). Can you please give me some advice on how to modify my return?</p>
  
  <p>Now my web service returns as following:</p>
  
  <pre><code>      &lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"&gt;
      &lt;S:Body&gt;
          &lt;ns2:extractCSResponse xmlns:ns2="http://ws/"&gt;
              &lt;ROW xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string"&gt;&lt;Firstname&gt;Mark&lt;/Firstname&gt;&lt;Lastname&gt;Thomas&lt;/Lastname&gt;&lt;ID&gt;1112546&lt;/ID&gt;&lt;/ROW&gt;
              &lt;ROW xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xs:string"&gt;&lt;Firstname&gt;Mike&lt;/Firstname&gt;&lt;Lastname&gt;Jackson&lt;/Lastname&gt;&lt;ID&gt;1112547&lt;/ID&gt;&lt;/ROW&gt;
          &lt;/ns2:extractCSResponse&gt;
      &lt;/S:Body&gt;
  &lt;/S:Envelope&gt;
  </code></pre>
  
  <p>My return needs to look like this:</p>
  
  <pre><code>&lt;S:Body&gt;
          &lt;ns2:extractCSResponse xmlns:ns2="http://ws/"&gt;
              &lt;ROWS&gt;
                  &lt;ROW&gt;
                      &lt;Firstname&gt;Mark&lt;/Firstname&gt;
                      &lt;Lastname&gt;Thomas&lt;/Lastname&gt;
                      &lt;IDname&gt;1112546&lt;/IDname&gt;
                  &lt;/ROW&gt;
                  &lt;ROW&gt;
                      &lt;Firstname&gt;Mike&lt;/Firstname&gt;
                      &lt;Lastname&gt;Jackson&lt;/Lastname&gt;
                      &lt;IDname&gt;1112547&lt;/IDname&gt;
                  &lt;/ROW&gt;
              &lt;/ROWS&gt;
          &lt;/ns2:extractCSResponse&gt;
      &lt;/S:Body&gt;
  </code></pre>
  
  <p>Java code below:</p>
  
  <pre><code>@WebService(serviceName = "GetCS2")
  @Stateless()
  public class GetCS2 {
  
      /**
       * This is a sample web service operation
       */
      @WebMethod(operationName = "extractCS")
      @WebResult(name = "ROW")
      public List extractCS()
      {
          List l = new ArrayList();
  
          //username and password for database connection
          String userName = "username";
          String password = "password";
  
                //db connection
              try
              {
                  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  
                  String url = "jdbc:sqlserver://172.19.125.222:1433"+";databaseName=Test";
                  Connection con = DriverManager.getConnection(url, userName, password);
  
                  Statement stmt = con.createStatement();
                  ResultSet rs = stmt.executeQuery("select * from list");
  
                  //loop through selection
                  while(rs.next())
                  {               
                      l.add("&lt;Firstname&gt;" + rs.getString("fn") + "&lt;/Firstname&gt;" + "&lt;Lastname&gt;" + rs.getString("ln") + "&lt;/Lastname&gt;" + "&lt;IDname&gt;" + rs.getDate("ID") + "&lt;/ID&gt;");
                  }
  
                  //close connections
                  stmt.close();
                  rs.close();
                  con.close();
  
              } catch(SQLException e)
              {
                  System.out.println("SQL Exception: " + e.toString());
              }
              catch(ClassNotFoundException cE)
              {
                  System.out.println("Class Not Found Exception: " + cE.toString());
              }
  
              return l;
  
      }
  }
  </code></pre>