EJB design: How to provide Xml Data for other client like VB,Asp in Ejb???

  1. Now, I want to transfer my data in the network, my client maybe a Jsp/Servelt, or a Delphi client. So I should transfer my data in xml format.
       But, I don't know how to transfer a ResultSet into Xml Object that can be read by Delphi client? I think i should provide a string stream in xml format? but i don't know how to solve it? sigh, there are too many tech about xml for me to select...
  2. Here's a simple hack for generating XML from a ResultSet. It came from the top of my head and I haven't tested it in anyway, but I think it should work (for the basic numeric, alphanumeric and time-related SQL types).

     * Returns an XML representation of the given ResultSet.
    private String resultSetToXml(ResultSet rs)
        ResultSetMetaData rsmd = rs.getMetaData();
        int numberOfColumns = rsmd.getColumnCount();
        int row = 0;

        StringBuffer xml = new StringBuffer(1000);
        xml.append("<?xml version=\"1.0\"?>");
        while (rs.next())
            xml.append("<row number=\"" + row + "\">");
            for (int i=0; i < numberOfColumns; i++)
                Object obj = rs.getObject(i);
                xml.append(" name=\"" + rsmd.getColumnName(i) + "\"");
                xml.append(" type=\"" + obj.getClass().getName() + "\"");
                xml.append(" value=\"" + obj.toString() + "\"");

        return xml.toString();

    ...and the resulting XML should look like this:

    <?xml version="1.0"?>
      <row number="1">
        <column name="id" type="java.lang.Integer" value="123"/>
        <column name="price" type="java.lang.Float" value="123.45"/>
        <column name="timestamp" type="java.sql.Timestamp" value="2002-01-23 12:34:56.0"/>
      <row number="2">
        <column name="id" type="java.lang.Integer" value="456"/>
        <column name="price" type="java.lang.Float" value="543.21"/>
        <column name="timestamp" type="java.sql.Timestamp" value="2002-02-02 23:45:01.0"/>
  3. another way to could do it is to use webservices and have other clients call the webservice and get the results from the method , as the overall meaning of webservices is to provide operatiblity between different programming languages
  4. What about SUN's WebRowSet?