| Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML | ||||
|
||||
|
|
||||
| Tutorial Categories: Ajax
| Articles
| JSP
| Bioinformatics
| Database
| Free
Books |
Hibernate
| J2EE
| J2ME
| Java
| JavaScript
| JDBC
| JMS
| Linux
| MS
Technology |
PHP
| RMI
| Web-Services
| Servlets
| Struts
| UML
|
|
||||||||||||||||||||||||||||||
|
Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs |
||||||||||||||||||||||||||||||
Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.
Copyright © 2007. All rights reserved.
Current Comments
8 comments so far (post your own) View All Comments Latest 10 Comments:Tutorial is very helpful.
You can have more meaningful method names instead of writing in main methods.
Thanks
Posted by Sree on Monday, 12.8.08 @ 07:06am | #82510
Dear sir
i want to know how to store XML documents into RDBMS by java.
I am difficult in position about that. So please help me sir.
i want to get java example coding about that sir
please help me
Best regards,
Tin Maung
Posted by Tin Maung on Saturday, 11.15.08 @ 07:49am | #81697
//Create a XML file in java using Parsers
import java.util.ArrayList;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.*;
import org.exolab.castor.xml.*;
import org.apache.xml.serialize.*;
public class MapAction extends HttpServlet {
//Connection con=null;
String path=null;
ArrayList arllist;
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
// MapForm mf=new MapFrom();
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String first = "3000";
String second="4000";
String caption="This Weeks meals plan";
String palette="5";
String shownames="1";
String showvalues="0";
String useRoundEdges="1";
String legendBorderAlpha="0";
String formatNumbersScale="0";
String numDivLines="11";
String yAxisMaxValue="6000";
String yAxisMinValue="0";
String sun="Sun";
String mon="Mon";
String tue="Tue";
String wed="Wed";
String thu="Thu";
String fri="Fri";
String sat="Sat";
String root="chart";
String categories="categories";
String category="category";
String dataset="dataset";
try{
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.newDocument();
Element rootElement = document.createElement(root);
rootElement.setAttribute("caption",caption);
rootElement.setAttribute("palette", palette);
rootElement.setAttribute("shownames", shownames);
rootElement.setAttribute("showvalues", showvalues);
rootElement.setAttribute("useRoundEdges", useRoundEdges);
rootElement.setAttribute("legendBorderAlpha", legendBorderAlpha);
rootElement.setAttribute("numDivLines", numDivLines);
rootElement.setAttribute("formatNumbersScale", formatNumbersScale);
rootElement.setAttribute("yAxisMaxValue", yAxisMaxValue);
rootElement.setAttribute("yAxisMinValue", yAxisMinValue);
document.appendChild(rootElement);
Element categoriesElement = document.createElement(categories);
rootElement.appendChild(categoriesElement);
Element categoryElement = document.createElement(category);
categoriesElement.appendChild(categoryElement);
categoryElement.setAttribute("label", sun);
categoriesElement.appendChild(categoryElement);
/*categoryElement.setAttribute("label", mon);
rootElement.appendChild(categoryElement);
categoryElement.setAttribute("label", tue);
rootElement.appendChild(categoryElement);
categoryElement.setAttribute("label", wed);
rootElement.appendChild(categoryElement);
categoryElement.setAttribute("label", thu);
rootElement.appendChild(categoryElement);
categoryElement.setAttribute("label", fri);
rootElement.appendChild(categoryElement);
categoryElement.setAttribute("label", sat);
rootElement.appendChild(categoryElement);*/
//
String scheduled="ScheduledCalories";
String color="AFD8F8";
Element datasetElement = document.createElement(dataset);
datasetElement.setAttribute("seriesName", scheduled);
datasetElement.setAttribute("color",color);
datasetElement.setAttribute("showvalues", showvalues);
rootElement.appendChild(datasetElement);
//
String sset="set";
String s1="4567";
Element ssetElement = document.createElement(sset);
ssetElement.setAttribute("value",first);
datasetElement.appendChild(ssetElement);
rootElement.appendChild(datasetElement);
//
String current="CurrentCalories";
color="F6BD0F";
Element setvalueElement = document.createElement(dataset);
setvalueElement.setAttribute("seriesName", current);
setvalueElement.setAttribute("color",color);
setvalueElement.setAttribute("showvalues", showvalues);
rootElement.appendChild(setvalueElement);
//
String c1="2500";
Element csetElement = document.createElement(sset);
csetElement.setAttribute("value",second);
setvalueElement.appendChild(csetElement);
rootElement.appendChild(setvalueElement);
OutputFormat format = new OutputFormat(document);
format.setIndenting(true);
//to generate output to console use this serializer
//XMLSerializer serializer = new XMLSerializer(System.out, format);
//to generate a file output use fileoutputstream instead of system.out
XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File("D:\\map.xml")), format);
serializer.serialize(document);
System.out.println("XML FILE CREATED:SUCCESSFULLY");
}catch(Exception ex){
ex.printStackTrace();}
}
}
//output XML File like below
<chart caption='This Weeks meals plan' shownames='1' showvalues='0' useRoundEdges='1' legendBorderAlpha='0'
formatNumberScale='0' yAxisMinValue='0' yAxisMaxValue='5000' palette='5'>
<categories>
<category label='Sunday'/>
<category label='Monday'/>
<category label='Tuesday'/>
<category label='Wednesday'/>
<category label='Thursday'/>
<category label='Friday'/>
<category label='Saturday'/>
</categories>
<dataset seriesName='Scheduled Calories' color='AFD8F8' showValues='0'>
<set value='3702'/>
<set value='3999'/>
<set value='3172'/>
<set value='2762'/>
<set value='2856'/>
<set value='2846'/>
<set value='3132'/>
</dataset>
<dataset seriesName='Current Calories' color='F6BD0F' showValues='0'>
<set value='2500' />
<set value='2500'/>
<set value='2500' />
<set value='2500' />
<set value='2500' />
<set value='2500' />
<set value='2500' />
</dataset>
</chart>
Posted by Javed N on Saturday, 10.11.08 @ 11:41am | #81011
Hi,
Thanx this helped me a lot to understand Java DOM, and XML Parsing.
Thanks once again,
Shivey
Posted by Shivey Upadhyay on Monday, 10.6.08 @ 15:44pm | #80925
Could you please share the code which is for removing the elements from XML using XPP parser/SAX
Posted by kiran on Thursday, 05.15.08 @ 15:32pm | #60030
thanx sir this document really helped me in unders
Posted by Ramakrishnareddy.M on Thursday, 12.27.07 @ 16:06pm | #43951
thanx sir this document really helped me in understanding DOM.. its te best tutorial on DOM I ever searched. thanx again
Posted by muhammad umer on Friday, 08.24.07 @ 19:32pm | #24051
A nice tutorial we got. It will helpfull to every s/w engineer.
Posted by Balaji Ganta on Wednesday, 08.1.07 @ 12:48pm | #22415