Back to project page foodroid.
The source code is released under:
GNU General Public License
If you think the Android project foodroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.wmc.Registration; //from w w w . j a v a 2 s .c om import java.io.StringWriter; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Settings { public static final String DATABASE_URL = "jdbc:mysql://localhost/restaurant"; public static final String DATABASE_USER = "root"; public static final String DATABASE_PASS = ""; public static String generateXML(ResultSet rs) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.newDocument(); Element results = doc.createElement("branch"); doc.appendChild(results); ResultSetMetaData rsmd = rs.getMetaData(); int colCount = rsmd.getColumnCount(); while (rs.next()) { Element row = doc.createElement("Row"); results.appendChild(row); for (int i = 1; i <= colCount; i++) { String columnName = rsmd.getColumnName(i); Object value = rs.getObject(i); Element node = doc.createElement(columnName); node.appendChild(doc.createTextNode(value.toString())); row.appendChild(node); } } DOMSource domSource = new DOMSource(doc); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); StringWriter sw = new StringWriter(); StreamResult sr = new StreamResult(sw); transformer.transform(domSource, sr); String result = sw.toString(); return result; } public static String replace(String text, String searchString, String replacementString) { StringBuffer sBuffer = new StringBuffer(); int pos = 0; while ((pos = text.indexOf(searchString)) != -1) { sBuffer.append(text.substring(0, pos) + replacementString); text = text.substring(pos + searchString.length()); } sBuffer.append(text); return sBuffer.toString(); } }