
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.

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

i am also facing same problem.can any one help me for this?
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.