Share on Google+Share on Google+

Creation of xml
1 Answer(s)      6 years ago
Posted in : XML

Hi, I need to fetch details from my database and to create a xml file containing all those datas...My database datas are in key value pair...

AppID Label Value
12345 Applicant name XXXX
12345 Masterno       YYYY
12345 Batchno        ZZZZ
12345 Tradelicence   TTTT

On the execution of query select * from tablename where appid="+12345+".

An xml file should be generated ...My xml file should in this format XXXX YYYY ZZZZ TTTT

Can u please send me the code fulfilling all my requirements!!!!


View Answers

April 27, 2011 at 12:42 PM

import java.sql.*;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;

 public class CreatXMLFile{
  public static void main(String[] args) throws Exception{
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder =documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.newDocument();
    Element rootElement = document.createElement("APPID");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from data where appID=12345");
           String element[]=new String[4];
           String data[]=new String[4];
           int i=0;
           element[i] = rs.getString("label");
           data[i]= rs.getString("value");
           for(int j=0;j<element.length;j++){
           Element em = document.createElement(element[j]);

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result =  new StreamResult(new File("C:/app.xml"));
        transformer.transform(source, result);
        System.out.println("XML File has been created succesfully");

Before running the above code, replace your key 'Applicant name' with either Applicant_Name or with ApplicantName because xml file does not allow to leave any space in the tag.

Related Tutorials/Questions & Answers:
Creation of xml
Creation of xml  Hi, I need to fetch details from my database and to create a xml file containing all those datas...My database datas are in key... of query select * from tablename where appid="+12345+". An xml file should
xml file creation in java
xml file creation in java  how to create xml file in java so...; Please visit the following links:   
xml creation in java
xml creation in java  HI, I need a java program to create an xml file... therez a tutorial in your site to create an xml file at but this isn't creating a file, its just
Creation of methods
Creation of methods  I have a only single class and its having only one method ie., main method only.... i need to develop another method that is to reduce my switching code package; import java.util.Scanner
bean creation exception
bean creation exception  hi i am getting exception while running simple spring ioc program Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class
How to: generic array creation
How to: generic array creation  How to: generic array creation
object creation - Subversion
object creation in Java  In how many ways we can create objects in Java
object creation - Java Beginners
object creation  I need object creation in depth(with stack,pc registers).Any one can provide me if possible with video/audio
XML  How i remove a tag from xml and update it in my xml
xml  validate student login using xml for library management system
xml  validate student login using xml for library management system
xml  why the content written in xml is more secure
exe file creation - JDBC
exe file creation   hi i have done a project in java swings.project name is format migrator.means db migrator. now my aim is create EXE FILE for my project. pls do consider
creation of installer - Java Magazine
creation of installer  plz tell me how can be create installer for any developed application in java?  visit the following url it will helps u
xml  what is name space,xml scema give an example for each   XML Namespaces provide a method to avoid element name conflicts.They are used for providing uniquely named elements and attributes in an XML document
XML  create flat file with 20 records. Read the records using xml parser and show required details
XML  please tell me how i remove one tag out of all similar type of tags in xml
xml  how can i remove white space and next line when i copy stream to xml file
XML  Hi...... Please tel me about that Aren't XML, SGML, and HTML all the same thing? Thanks
xml  what is xml   Extensible Markup Language (XML... that is both human-readable and machine-readable. It is defined in the XML 1.0... gratis open standards. The design goals of XML emphasize simplicity, generality
xml  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
XML  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
Random Creation of password
Random Creation of password  Dear Sir I have created a form with some details in it.When clicking on the submit button it gives me a password .....Details and the password is saved in the database....The password has
creation of a form - JSP-Servlet
creation of a form  how to create a question paper using JSP code  Hi Friend, We have taken radiobuttons in our application, you can take textarea, textfield etc. Create a table ans(ques,op1,op2,op3,op4,op5,ans
XSD Creation. - WebSevices
XSD Creation.  When I try to generate xsd from java object. It is generating XSD file finely. But the problem is it isgenerating XSD file elements in alphabetical order. can u please sujest me how can we do that one. I tried
Session creation and tracking
Session creation and tracking  1.Implement the information persistence across servlet destroy or servlet container start/stop. Write a servlet such that when it is stopped (either by container shutdown or servlet stop
creation of database - SQL
creation of database  hi, where to and how to execute SQL queries?   Hi nanju mysql>CREATE DATABASE search; mysql> SHOW DATABASES; mysql> USE search mysql>create table Emp (fname VARCHAR(20
creation button using objective c
creation button using objective c  creation button using objective c
oXygen XML Editor
oXygen XML Editor       The simple and elegant look of the <oXygen/> XML Editor combined with the complete coverage of the XML editing features have made
Chatbox creation problem
Chatbox creation problem  i have one chat box in my web site and i assigned fixed position to that div.that is workin in mozill but it is not working in ie . thank you`print ("<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
creation of table using a Java swing
creation of table using a Java swing  how to create a table dynamically in Java swing
Java Spring Hibernate Struts Training were to start with xml, XSD and java write a program that Implement an integrated COM client server to add two visuall studio 2010 Building a Parent Child relationship XML how i connect two page xml question struts cfg file for DispatchAction with mysql db Creating custom output using XMLUnit - MatchTracker duplicates the output data Related to XML Related to XML Reading child of child nodes in xml Reading multiple xml files Spliting Large XML and one by one Moved to Output Folder XMl and Java web services project download xml file from website using java code Download how to create an xml file in following clear format Conditional increment in xslt Conditional increment in xslt Conditional increment in xslt HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP? xml and servlets xml and servlets Question about parsing XML document with DOM in JAVA. Removal of XML header Converting PHP page with flash to JSP page without flash saving data in xml Doubt about Xstream Converter Reading xml file using dom parser in java with out using getelementby tag name xml dynamically how to change attiribute values in xml XML Schema xml xml sax parser for xml parsing xml using sax xml to html via java i want java code for this xml file...please show me.. SAX Parser for huge XML file xml parsing "opening video data error" in j2me XML to JSP mapview1 mapview searchbar searchbar jsonparsing xmlparsing retrieve multiple attribute values retrieve multiple attribute values


Advertisement null