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



Home Answers Viewqa Development-process storing data in xml file using jsp

Have Programming Question? Ask it here!
 
 
 


Mahesh Yadav
storing data in xml file using jsp
2 Answer(s)      2 years and 3 months ago
Posted in : Development process


hi i am storing data in xml file using jsp.in this when i enter data into xml file i am getting xml declaration for each specified data?can any one help me to prevent this?


Advertisement
View Answers

April 12, 2012 at 4:27 PM


<%@page import="java.io.*,org.w3c.dom.*,javax.xml.parsers.*,javax.xml.transform.*, javax.xml.transform.dom.*,javax.xml.transform.stream.*,javax.xml.*"%> 
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
  </head>
  <body>
    <P>
    <form>
      <P>Name       
        <input type="text" name="text1"/>
      </P>
      <P>Address   
      <input type="text" name="text2"/></P>
      <P>Contact    
      <input type="text" name="text3"/></P>
      <P>Email        
      <input type="text" name="text4"/></P>
      <P>                                                                             
      </P>
      <P>                                                      
        <input type="submit" value="Submit" name="submit"/>
      </P>
    </form></P>
      <%!


     public void createXmlTree(String name,String address,String contact,String email) throws Exception {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
        Document doc = docBuilder.newDocument();
        System.out.println(name);
        Element root = doc.createElement("Student");
        doc.appendChild(root);

        Element child1 = doc.createElement("Name");
        root.appendChild(child1);


        Text text1 = doc.createTextNode(name);
        child1.appendChild(text1);

        Element child2 = doc.createElement("Address");
       root.appendChild(child2);

        Text text2 = doc.createTextNode(address);
        child2.appendChild(text2);

        Element child3 = doc.createElement("ContactNo");
        root.appendChild(child3);

        Text text3 = doc.createTextNode(contact);
        child3.appendChild(text3);

        Element child4 = doc.createElement("Email");
        root.appendChild(child4);

        Text text4 = doc.createTextNode(email);
        child4.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:/emp.xml");
        FileWriter fw=new FileWriter(file,true);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(xmlString);
        bw.flush();
        bw.close();    
    }%>


April 12, 2012 at 4:27 PM


continue....

<%
    String name1,address1,contact1,email1;
    name1 = request.getParameter("text1");   
    address1 = request.getParameter("text2"); 
    contact1 = request.getParameter("text3"); 
    email1 = request.getParameter("text4");
    String name=name1;
          String address=address1;
          String contact=contact1;
          String email=email1;


      try
      {
          System.out.println(name);
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = builderFactory.newDocumentBuilder();
            Document doc = docBuilder.newDocument();


            createXmlTree(name,address,contact,email);


        out.println("<b>Xml File Created Successfully</b>");
      }
      catch(Exception e)
      {
        System.out.println(e);
      }

      %>
      </body>
    </html>


Related Tutorials/Questions & Answers:
Produces XML file but format not correct for storing data using JSP and XML
Produces XML file but format not correct for storing data using JSP and XML  hii I have created a project using JSP and XML as database to store data entered by user in XML file ,It stores data entered in XML file
storing data in xml - XML
storing data in xml  Can u plz help me how to store data in xml using...,name,address,contactNo,email); System.out.println("Xml File Created...(); File file = new File("c:/employee.xml"); BufferedWriter bw = new
Advertisements
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
how to append data to XML file in proper format using JSP
how to append data to XML file in proper format using JSP  hello i was appending my XML file to add more data entered by user in JSP page.But not getting XML file in proper format as XML rules.lease help me to get XML file
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page
How to store data entered in JSP page by a user in XML file & later retrieval... .I am using Jdeveloper..xml file creates successfully,but i want data entered by user to be stored in xml file.here you have entered data in JSP file
Storing Data (Retrieved from a XML Document) to a File
Storing Data (Retrieved from a XML Document) to a File... to store data (retrieved from the XML document) to a specified file (with ... that helps you in storing the data to a specified file in different format. After
how to store data in XML file - JSP-Servlet
how to store data in XML file  hi i have to store the data for example user id and password in a xml file the input userid and password will be coming from jsp middle ware servlet how to do that?   Hi friend
storing xml into database - XML
storing xml into database   hi i have an xml file it contains... .......with it i know how to persist a simple xml file into data base but i m finding some difficulty to start with i m sending u the xml file
Sava data from Form to XML file using strutrs
Sava data from Form to XML file using strutrs  I'am a biginner with struts want so save data from my form in an Xml file using struts but i'm searching witout finding a solution thanks fo your help
Hibernate Data Filter using XML
In this section, you will learn to filter data using XML mapping file
sorting and filtering the displayed table data using jsp and xml
sorting and filtering the displayed table data using jsp and xml  I have created a xml file and a jsp file, which uses DOM parser to display the content of xml file in web page. Now I would like to sort and filter those data
Stored Data in XML File using Servlet
Stored Data in XML File using Servlet  ... to stored data in xml file using Servlet  We have created  file login.jsp... in xml file. It creates XML file with its version and encoding and display
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?
HOW TO STORE MULTIPLE EMPLOYEE DETAILS TO XML FILE USING JSP?  HELLO... EMPLOYEES SHOULD BE SAVED IN XML FILE AND MY SQL DATABSE TABLES AT A TIME, AND ALSO HELP ME OUT WITH HOW TO VIEW THE STORED DATA IN XML FILE USING EMPNAME. PLEASE
How to store data entered by User in JSP page in XML file
  JSP store data entered by user into XML file 1)form.jsp: <html>...How to store data entered by User in JSP page in XML file  How to store data entered by user in JSP page to be saved in XML file.On clicking submit
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 xml file in jsp
parsing xml file in jsp  example that pars XML file in JSP
sorting and storing data
sorting and storing data   sorting and storing data in UITableView
Read data from excel file and update database using jsp
Read data from excel file and update database using jsp  read data from excel file and update database using jsp Hi, I am using a MySQL database... upload excel file and update database using JSP ? Thanks in Advance
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
Get Data From the XML File
Get Data From the XML File       Here you will learn to retrieve data from XML file using SAX parser... of program: In this example you need a well-formed XML file that has some data (Emp
iphone storing and fetching data
iphone storing and fetching data  How to store and fetch data in an iphone application
storing data into flat files
storing data into flat files  how can i retrive data from database and store data in flat files   Hi Friend, Try the following code...(); File file=new File("data1.txt"); Class.forName
Insert XML file data to database
Insert XML file data to database In this tutorial, you will learn how to insert the xml file data to database using dom parser. You all are aware of XML... to read the xml file data and save the values of an XML file to a Database
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
JSP and XML .data store nd retrieve
JSP and XML .data store nd retrieve  I have made a form in jsp having... in xml file.How can i store data entered by user in XML file and later retrieve data in another jsp page using retrieve submit button.Please tell step by step
Remote file storing in mobile
Remote file storing in mobile  Hai.. i want to do my semester project..i have selected a topic "Remote file storing in mobile"..it is in the form like any Java enabled GPRS based mobile phone users can store their images,video
Remote file storing in mobile
Remote file storing in mobile  Hai.. i want to do my semester project..i have selected a topic "Remote file storing in mobile"..it is in the form like any Java enabled GPRS based mobile phone users can store their images,video
Retrieve data from xml using servlets
Retrieve data from xml using servlets  Hi plz send me the code for retrieving the data from xml File using Servlets.   Hi, Do you want.... Thanks Deepak   Hi, Here is one tutorial: Create XML File using Servlet
how to save html form data into .csv file using only jsp.
how to save html form data into .csv file using only jsp.  Dear all, I am developing a website only using jsp and html. i need to save the form data into a .csv file using jsp. can anyone give me any sample solution or tutorial
Getting Data from XML File (Document)
Getting Data from XML File (Document)   ... from a XML file. All xml files store the data. You can add and modify the data...: This program helps you in retrieving the data from a XML file. It takes a xml file
project in JSP and XML(to store data)
project in JSP and XML(to store data)  I need to complete an assignment in JSP and using XML as Database ,Please help me to complete... of JSP Web Application demonstrating web technology concepts? Create n
Storing and Reading data
Storing and Reading data   Hello, I'm developing a GUI application as part of an assignment but stuck on how my program stores and reads the data... that limits the data type and the character size that can be entered
Retrieving XML Data Using GWT
Retrieving XML Data Using GWT       This Example Describes the way of retrieving XML file Data from... a xml file named customerRecord.xml. customerRecord.xml
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.
Retrieving XML Data Using GWT
Retrieving XML Data Using GWT       This Example Describes the way of retrieving XML file Data from the server using GWT. The basic building block for running
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
complex xml parsing and storing in database - XML
complex xml parsing and storing in database  Hi Experts ,i want to parse my xml document and store it in mysql database. This is my code. How to parse this complex data. EDI_DC40 800 0000000000557748
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
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
how to search data in xml files using php
how to search data in xml files using php  So I want to create a website that allows me (or others) to type in a words and select a relevent search, and have it search multiple XML pages on server The XML documents are setup
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
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 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
Reading Text file and storing in map
Reading Text file and storing in map  Hi I have multiple text files. I want to read thoses files and store those records in map. Map will be of "LinkedHashMap<String, Map<String, String>>" type. Please let me know
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
Storing content from file path to an array
would like to access the "Animation.txt" file from this path and store the contents in this text file to an array. I am using jsp. I can access my path but how...Storing content from file path to an array  Hi, I have a path
How to generate xml file using xpath
How to generate xml file using xpath  Hi, I have a requirement... to make a xml using that,. It would be great is you can help me out with how to make a xml using xpath. Thanks in Advance, Sanjay   Hi Friend, Please
Retrieving Data From the XML file
jsp file. We have a XML file in which we have some data. What we need... Retrieving Data From the XML file  ... and expose XML information using the JAXP with a JSP page. This example
JAXB Create XML File And Get Data From XML
JAXB Create XML File And Get Data From XML In this section we will read about how to create XML file and how to convert XML file's data to Java Object... using Java Object then we will read that XML data as Java Object again
Advertisements
 

 

 

DMCA.com