Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC xml configuration file

Have Programming Question? Ask it here!
 
 
 


geetha
xml configuration file
1 Answer(s)      4 years and 8 months ago
Posted in : JDBC



Advertisement
View Answers

December 18, 2009 at 4:21 PM


Hi Friend,

Try the following code:

<%@page import="java.io.*"%>
<%@page import=" org.w3c.dom.*"%>
<%@page import=" javax.xml.parsers.*"%>
<%@page import=" javax.xml.transform.*"%>
<%@page import=" javax.xml.transform.dom.*"%>
<%@page import=" javax.xml.transform.stream.*"%>
<%@page import=" java.sql.*"%>
<%!
public void createXmlTree(Document doc,String id,String name,String address,String contactNo) throws Exception {
Element root = doc.createElement("Employee");
doc.appendChild(root);
Element element1 = doc.createElement("Emp_ID");
root.appendChild(element1);
Text text1 = doc.createTextNode(id);
element1.appendChild(text1);

Element element2 = doc.createElement("Emp_Name");
root.appendChild(element2);
Text text2 = doc.createTextNode(name);
element2.appendChild(text2);

Element element3 = doc.createElement("Emp_Address");
root.appendChild(element3);
Text text3 = doc.createTextNode(address);
element3.appendChild(text3);

Element element4 = doc.createElement("Emp_ContactNo");
root.appendChild(element4);
Text text4 = doc.createTextNode(contactNo);
element4.appendChild(text4);

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");

StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);
String xmlString = sw.toString();

File file = new File("c:/employee.xml");
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
bw.write(xmlString);
bw.flush();
bw.close();

}
%>
<%
response.setContentType("text/xml");

try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root";, "root");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("Select * from employee where emp_id='2'");

String id="", name="",address="",contactNo="";
while(rs.next()){
id=rs.getString("emp_id");
name=rs.getString("emp_name");
address=rs.getString("emp_address");
contactNo=rs.getString("contactNo");
}
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
createXmlTree(doc,id,name,address,contactNo);

out.println("<b>Xml File Created Successfully</b>");

}
catch(Exception e){}
%>

For more information,visit the following link:

http://www.roseindia.net/jsp/jsp-write-xml.shtml

Thanks


Related Tutorials/Questions & Answers:
xml configuration file - JDBC
xml configuration file  Hi, Could you please tell me how to write a xml configuration file . We have mysql database in some other system. I have... to create a xml file. Please help me out. Thank you  Hi Friend, Try
Configure the configuration file
Configure the configuration file  How do I configure the configuration file
Advertisements
Hibernate configuration file
This tutorial helps you in understanding the configuration file of Hibernate
Hibernate Configuration File
Hibernate Configuration File In this tutorial you will learn about the hibernate configuration file. To define a Hibernate Configuration info a resource file named hibernate.cfg.xml is used. Using this configuration file various
Hibernate Configuration File
Hibernate Configuration File In this section we will read about the hibernate configuration file. In this file we will see how we can provide the database connection information to a file. Hibernate Configuration file i.e.
What are the concepts and purpose of Spring configuration file.
What are the concepts and purpose of Spring configuration file.  Hi, What are the concepts and purpose of Spring configuration file. Thanks
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration file
Creating XMl file - XML
Creating XMl file   I went on this page: http://www.roseindia.net/xml/dom/createblankdomdocument.shtml and it shows me how to create an XML file, however there is something I don't understand. I have to create an XML file
xml file display - XML
xml file display   - - - - ADL SCORM CAM 1.3 - - session3 - Online Instructional Strategies that Affect Learner... code to display the above xml file in tree structure where
Sorting Xml file - XML
Sorting Xml file  I have an xml file like this: Smith USA... sort my xml file. Here is my xslt..., my ouput file will be like this: Amy AUC Bob USA John UK
splitting large xml file. - XML
splitting large xml file.  Hi, I have a large xml file(1G) and a schema (XSD) i need to split this xml to small xml files (~20M) that will be valid by the schema
parsing xml file in jsp
parsing xml file in jsp  example that pars XML file in JSP
executio of xml file
executio of xml file  how to execute xml file , on web browser
How to create XML file - XML
How to create XML file  Creating a XML file, need an example. Thanks!!  To create XML file you need plain text editor like note pad. After creating your file save it with .xml extension.  Hi,Java programming
how to read this xml file - XML
how to read this xml file  i want to read this xml file using java... read i have tried lot more , but i am not able to read this xml file...[])throws Exception { File f=new File("C:/data.xml"); DocumentBuilderFactory
Run XML file
Run XML file  Hi.. How do I execute or run an XML file? please tell me about that Thanks
xml file creation in java
xml file creation in java  how to create xml file in java so that input should not be given from keyboard. and that file should be stored.   Please visit the following links: http://www.roseindia.net/tutorial/java/xml
How to prepare XML file?
How to prepare XML file?  Hi, I want to prepare XML File, can you... you create an XML file.. Create XML File using Servlet How to generate build.xml file Complete Hibernate 3.0 and Hibernate 4 Tutorial Thanks
retrieve in xml file in struts2
retrieve in xml file in struts2  i am using struts2 and trying... can i get back the value from the xml file in the ajax function and print... properties file using ajax. i now put the values from properties file to map
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations  how to write code to attach multiple files and upload using spring mvc 2.o with xml configuration with out annotations? please
Spring Null value, Set null value in Springs configuration file
Spring Null value, Set null value in Springs configuration file In this example you will see how to set null value in the Spring configuration file. NullBean.java package spring.nullvalue.example
questions from an xml file
questions from an xml file  i am developing online bit by bit exam for that i retrieved questions from an xml file but when i retrieved using jsp i am getting all questions at a time in a single page.but i want to show one
Struts Configuration file - struts.xml
Struts Configuration file - struts.xml      .... The struts.xml File The Struts 2 Framework uses a configuration file (struts.xml... is the core configuration file for the framework and it should be present
how to convert .xml file to csv file
how to convert .xml file to csv file  how to convert .xml file to csv file
How to convert XML file to database ?
How to convert XML file to database ?  How to convert XML file to database
how to seach a keyword in a xml file - XML
how to seach a keyword in a xml file  i have a xml file. i wanted to read and store all the tag values. i have a html form in which when i enter some keyword say "a" then it has to display the tag values starting with a letter
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C
parsing XML file to get java object - XML
parsing XML file to get java object  Hello, I'm facing a problem in parsing XML file to get the java object. I've tried to retrieve data from XML file using SAX parser. my XML file structure is the following
How to write to xml file in Java?
How to write to xml file in Java?  Hi Friends, Can anyone help me how to write in xml file in Java programming. Please fill free to give example or reference website for getting example.   Hi, To write in xml file
How to create one xml file from existing xml file's body?
How to create one xml file from existing xml file's body?  Hi, i'm working with content optimization system.I want to know how we can take all data from an xml doc's body to develope another xml with that content.I'm using JDOm
Reading a xml file - JSP-Servlet
Reading a xml file  how to read a xml file using jsp and then i have to retrive a data from that file use it in code?  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/parsing-xml.shtml
how to convert text file to xml file in java. - XML
how to convert text file to xml file in java.  Hi all, I m having some problem. Problem is I want to convert a text file which is having the no of record(i.e no of different line of information)to a xml file through java
how to modify content of XML file
to xml file to replace "XYZ".Every time with the content of text box the file should...how to modify content of XML file  hi, I want to modify content of a xml file.There are two tags of similar name say <ContentName>C:\Myinfo
Reading a xml file - JSP-Servlet
Reading a xml file  Thanks for ur answer sir but problem is that i have to do a reading a xml file of a employee record and then i have to use a employee details to send mail to those employees how to do i sir please help me
Interceptors Configuration using Java or XML
In this section, you will learn about how to configure interceptors using Java or XML
SAX Parser for huge XML file
SAX Parser for huge XML file  Hi.... if the XML file is small...("Enter XML file name:"); String xmlFile = bf.readLine(); File file = new File...(); } } } .. What if the xml file is very big or huge file? and sometimes we wont
Static Resources Configuration
In this section, you will learn about Static Resources Configuration through MVC Java config and XML Namespace
Java get XML File
Java get XML File     ... the XML file. For this, you need to create a XML file. Here is the employee.xml file: <?xml version="1.0"?> <company>
How read xml file value in dojox chart - XML
How read xml file value in dojox chart  How to read the xml file value in dojox chart
xml file reading using java
xml file reading using java  hi deepak I want to read some data from xml file and send that output to particular email address using java   import org.w3c.dom.*; import org.w3c.dom.Node; import javax.xml.parsers.
Writing xml file - Java Beginners
XmlServlet().createXmlTree(doc); System.out.println("Xml File Created...Writing xml file  Thank you for the quick response The values which... from xml tree StringWriter sw = new StringWriter
converting an xml file in relational database objects
converting an xml file in relational database objects  converting an xml file in relational database objects
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
validation in struts2 using .xml file
validation in struts2 using .xml file  how to do xml validation in struts2 on dynamic fields   Hello Friend, Please visit the following link: http://www.roseindia.net/struts/struts2/struts2validation.shtml Thanks
parsing word xml file using SAX parser - XML
parsing word xml file using SAX parser  i am parsing word 2003's XML file using SAX.here my question is,i want to write some tag elements which... this xml file and write that xml part into file? can somebody
Store XML file into Sqlserver Database
Store XML file into Sqlserver Database  Code for storing a typical XML file into SQl server database in 1 or more tables using asp.net using C#. <?xml version="1.0" ?> <!DOCTYPE PubmedArticleSet (View Source
downloading created xml file - Java Beginners
need to create an xml file and when a button is clicked it has to prompt me for saving the xml file so i created xml file successfully and whats the problem is when i saved the file after prompting it is saved in .do format instead of xml
How to Split a large XML file using java?
How to Split a large XML file using java?  How can we split a 500MB Xml file?I know how to split xml file after reading the entire document in a file.Here we cannot load the entire file as it is a large file
What is XML?
: XML file is simple text file with .xml extension. XML file is used... in the XML format. XML is also used by the applications to store the configuration... is simple example of XML file: <Invoice>    <to>ABC
Storing properties in XML file
Storing properties in XML file     ... File. JAXP (Java API for XML Processing) is an interface which provides parsing... in xml file:- File f=new File("2.xml"):-Creating File in which properties
 

 

 

DMCA.com