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 but not in proper format .The root element (which is unique) creates again and again when data is entered in XML file. XML file created :

<?xml version = '1.0' encoding = 'UTF-8'?>
<Stu>
   <Student>
      <Name>111</Name>
      <Address>222</Address>
      <ContactNo>333</ContactNo>
      <Email>444</Email>
   </Student>
</Stu><?xml version = '1.0' encoding = 'UTF-8'?>
<Stu>
   <Student>
      <Name>11</Name>
      <Address>111</Address>
      <ContactNo>1</ContactNo>
      <Email>11</Email>
   </Student>
</Stu><?xml version = '1.0' encoding = 'UTF-8'?>
<Stu>
   <Student>
      <Name>55</Name>
      <Address>ww</Address>
      <ContactNo>ww</ContactNo>
      <Email>1232</Email>
   </Student>
</Stu>

My JSP code for the given program is :

<%@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/xml; 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>


      <%!


     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();


       //doc = docBuilder.parse("c:/air3.xml");
       //Element root = doc.getDocumentElement();

        Element root = doc.createElement("Stu");
        doc.appendChild(root);
        Element child = doc.createElement("Student");
        root.appendChild(child);

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


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

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

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

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

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

        Element child4 = doc.createElement("Email");
        child.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:/air3.xml");
        FileWriter fw=new FileWriter(file,true);
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(xmlString);
        bw.flush();
        bw.close();    
    }%>


<%
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
  {
        createXmlTree(name,address,contact,email);
        out.println("<b>Xml File Created Successfully</b>");
  }
  catch(Exception e)
  {
    System.out.println(e);
  }

  %>
        <P>                                                      
        <input type="submit" value="Submit" name="submit"/>
      </P>
  </form></P>
  </body>
</html>

I am using Jdeveloper ,program runs correctly,forms XML file also(wrong format),shows result in JSP page but server shows the following error also:

XML-22900: (Fatal Error) An internal error condition occurred.

View Answers

March 9, 2011 at 5:09 PM

Kidnly help of out of this problem..i need the solution for that.. i tried a lot but get the same output again and again. Kindly help me Thanks


April 12, 2012 at 2:27 PM

i am also facing same problem.can any one help me for this?

Ads









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... XML file also(wrong format),shows result in JSP page but server shows
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
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
database data in xml format
database data in xml format  HI, i want to display the database data in the xml format(not as xml file ) on the console using DOM. help will be appreciated. THANKS K.K
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
parsing xml file in jsp
parsing xml file in jsp  example that pars XML file in JSP
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
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
Hibernate Data Filter using XML
In this section, you will learn to filter data using XML mapping 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
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
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
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.
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
XML to JSP
an xml file and display the data into jsp file...XML to JSP  How to access the following XML tag Title tag in JSP   Please visit the following link: http://www.roseindia.net/jsp
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
how to create an xml file in following clear format
how to create an xml file in following clear format  anyone please help me out to create this file,,. <Tasks> <Taskid>...;Taskid>3 <Taskname>Integration <Project>Assinment JSP
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
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
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
What is XML?
booking application may send the data in xml format to the credit card processing... or other format. XML is designed to transport and store the data. XML...: XML file is simple text file with .xml extension. XML file is used
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
How to convert excel file int xml format in java
How to convert excel file int xml format in java  How to read excel file(xls) which is stored in any directory(D://) and convert it into xml format in java and place in any directory(E://).Can any body provide the code
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
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
Storing and retrieving data alongwith image in mysql db using jsp
Storing and retrieving data alongwith image in mysql db using jsp  I... | | | file_data | longblob | YES | | NULL... = connection.prepareStatement("insert into file(file_data) values(?)"); fis = new FileInputStream(f
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
jsp and xml - XML
jsp and xml  An example of retrive data from xml using JSP.  HiThis retrive data from xml using jsp.airLineShedule.jsp<%@ page...;/body></html>airLineShedule.xml<?xml version="1.0" encoding
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell... ServletException, IOException { response.setContentType("text/xml"); FileRead fr
How to get xml file form http port using web service
How to get xml file form http port using web service  hi I am suresh i am using netbeans 6.9 to develop a web service for getting xml from http port and use the xml data to convert it to java file and store it to DB. But i am

Ads