Package com.basiscomponents.db.export
Class XmlExport
- java.lang.Object
-
- com.basiscomponents.db.export.XmlExport
-
public class XmlExport extends Object
-
-
Constructor Summary
Constructors Constructor Description XmlExport()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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).static void
writeXML(ResultSet resultSet, String rootTagName, String entityName, Writer writer, DataRow baseDR, boolean useLabel)
Uses the given Writer object to write the ResultSet's content as XML to the output stream.
-
-
-
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:
<p>Let&s write a "Hello World" program!</p>
- Parameters:
s
- The String whose special characters should be replaced- Returns:
- The String with the escaped characters
-
-