|
Hi all,
I have used a strange approach to generating XML based on data retrieved from database and have consequently displayed it in HTML format using XSL here is the code ihave used: Properties pEnv = new Properties(); pEnv.load(new FileInputStream("C:\\jboss-2.4\\tomcat\\webapps\\ROOT\\jspxml\\abc.dtd"));//loaded my DTD file in same directory where my XML file will be generated try{ *****Creating a string that looks like XML***** String xmlG="<?xml version=\"1.0\" ?>\n"; xmlG=xmlG+"<!DOCTYPE abc >\n\n"; xmlG=xmlG+"<abc>\n"; v5=remote1.getEmployeeNames();//fetching data from database and writng it as part of string using EJB method call for(int i=0;i<v5.size();i++) { vRow=new Vector(); vRow=(Vector)v5.elementAt(i); xmlG=xmlG+"<people>\n"+ "<person>\n"+ "<name>\n"+ "<firstname>"+(String)vRow.get(1)+"</firstname>\n"+ "<lastname>"+(String)vRow.get(2)+"</lastname>\n"+ "<ecn>"+(String)vRow.get(0)+"</ecn>\n"+ "</name>\n"+ "</person>\n"+ "</people>"; } xmlG=xmlG+"</abc>"; ******making a xml file using the String***** FileOutputStream f= new FileOutputStream("C:/jboss-2.4/tomcat/webapps/ROOT/jspxml/myxml.xml"); DataOutputStream d= new DataOutputStream(f); d.writeBytes(xmlG); }catch(Exception ex) { out.println(" Exceptionin in exp.jsp: "+ex); } response.sendRedirect("bookdata.jsp");//here,the xml file generated together with xsl(written separately) is being converted into html format for display using Taglibs. %> I have not used any XML parser for the xml generation ...this works...I had also written a DTD . Is this the correct approach...what would the negative implications be...can anyone comment.. thanks in advance, Saurabh http://www.sys-con.com/java/list.cfm |
