Class XmlExport


  • public class XmlExport
    extends Object
    • Constructor Detail

      • XmlExport

        public XmlExport()
    • Method Detail

      • writeXML

        public static void writeXML​(ResultSet resultSet,
                                    String rootTagName,
                                    String entityName,
                                    Writer writer,
                                    DataRow baseDR,
                                    boolean useLabel)
                             throws Exception
        Uses the given Writer object to write the ResultSet's content as XML to the output stream. The given root tag name will be used as the XML's root tag, and the give entity name will be used as surrounding tag for each of the ResultSet's DataRow objects.

        Usage:
         StringWriter w = new StringWriter();
         ResultSet rs = new ResultSet();
         
         DataRow dr = new DataRow();
         dr.setFieldValue("feld1", "TEST1");
         dr.setFieldValue("feld2", "TEST2");
         rs.add(dr);
         
         dr = new DataRow();
         dr.setFieldValue("feld1", "TEST1");
         dr.setFieldValue("feld3", "TEST3");
         rs.add(dr);
         
         ResultSetExporter.writeXML(rs, "articles", "article", w);
         w.flush();
         w.close();
         
         System.out.println(w.toString());
         
         FileWriter fw = new FileWriter("D:/test.xml");
         ResultSetExporter.writeXML(rs, "articles", "article", fw);
         fw.flush();
         fw.close();
         
        Parameters:
        resultSet - The ResultSet object whose content will be written in XML format.
        rootTagName - The name of the XML Root Tag to use.
        entityName - The name of the XML tag to use for each DataRow of the ResultSet.
        writer - The Writer object used to write the XML.
        baseDR - the data row, that holds the column sequence and the column labels (if available)
        useLabel - indicates if the label instead of the field name should be used
        Throws:
        Exception - Gets thrown in case the XML could not be written.
      • escapeHTML

        public static String escapeHTML​(String s)
        Replaces all characters from the given String whose ascii decimal value is >127 by the ascii decimal value preceeded by "&#" and followed by ";"(Without the quotes). Additionally replaces the following characters using the same mechanism: ",&,',<,>

        For example, the following String:

        <p>Let's write a "Hello World" program!</p>

        would become:

        &#60;p&#62;Let&#38;s write a &#34;Hello World&#34; program!&#60;/p&#62;

        Parameters:
        s - The String whose special characters should be replaced
        Returns:
        The String with the escaped characters