xml configuration file

xml configuration file

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
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
Advertisements
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
Configure the configuration file
Configure the configuration file  How do I configure the configuration file
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
Run XML file
Run XML file  Hi.. How do I execute or run an XML file? please tell me about thatADS_TO_REPLACE_1 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 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
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
Hibernate Configuration File
. A configuration file hibernate.cfg.xml may be written as : <?xml version='1.0...Hibernate Configuration File In this tutorial you will learn about the hibernate configuration file. To define a Hibernate Configuration info a resource file
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.
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
Hibernate configuration file
This tutorial helps you in understanding the configuration file of Hibernate
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
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
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
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
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
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
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
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
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 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
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
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:ADS_TO_REPLACE_1 <?xml version="1.0"?> <
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.
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:ADS_TO_REPLACE_1 http://www.roseindia.net/struts/struts2/struts2validation
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
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
More than one Faces Configuration file
More than one Faces Configuration file  Is it possible to have more than one Faces Configuration file
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
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
converting an xml file in relational database objects
converting an xml file in relational database objects  converting an xml file in relational database objects
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
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
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
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
graph generation from xml design file
graph generation from xml design file  how to search words in XML file with javascript. i have copied contents of XML file into word file. using searched keywords i would like to draw graph
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
How to build .XML file, please provide an example.
How to build .XML file, please provide an example.  Hello, I want to know how to build .XML file. If you can provide an example, that would be great... Thanks
write xml file with jsp useBean - JSP-Servlet
write xml file with jsp useBean  how to write into xml files with jsp... an org.w3c.dom.Document from XML. Save the xml file at bin file of C:\apache-tomat-5.5.23\bin... allows our application to obtain a Java XML parser. DocumentBuilderFactory
Transforming an XML File with XSL
Transforming an XML File with XSL       This Example gives you a way to transform an XML File with XSL in a DOM document. JAXP (Java API for XML Processing) is an interface which

Ads