aspose file tools*
The moose likes JSP and the fly likes converting to XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "converting to XML file" Watch "converting to XML file" New topic
Author

converting to XML file

midan myaa
Greenhorn

Joined: Nov 26, 2001
Posts: 8
Hi i am buildding a WEb based Questionnaire and i am trying to receive text from a jsp page i have created and print it out as XML. I have a createHeader.jsp file that asks for the number of questions you want to create so when i click it it take me to createQuestions.jsp where i can enter text. ie
Enter a Question, 4 choices and the Right anwser. When i submit it takes me to writeXML.jsp which write it as an XML file...

<%
String Tquestion = request.getParameter("questionText");

String answer1 = request.getParameter("choice1");
String answer2 = request.getParameter("choice2");
String answer3 = request.getParameter("choice3");
String answer4 = request.getParameter("choice4");
String Canswer = request.getParameter("cAnswer");
%>

<%
String home ="C:\\Tomcat\\FYProject\\lib\\";
String filename = request.getParameter("file");
String extension = ".xml";
String filePath = home + filename + extension;
BufferedWriter bw = new BufferedWriter(new FileWriter(filePath,true));
for(int i=0;i<2; i++) {

%>
<%
bw.write("<mc_QuestionType>");
bw.newLine();
bw.write(" <questionText>" +Tquestion+ "</questionText>");
bw.newLine();
bw.write(" <choice>" +answer1+ "</choice>");
bw.newLine();
bw.write(" <choice>" +answer2+ "</choice>");
bw.newLine();
bw.write(" <choice>" +answer3+ "</choice>");
bw.newLine();
bw.write(" <choice>" +answer4+ "</choice><br>");
bw.newLine();
bw.newLine();
bw.write(" <answer>" +Canswer+ "</answer>");
bw.newLine();
bw.write("</mc_QuestionType>");
bw.newLine();

}
bw.close();
%>
So this gets the parameter names of the TEXTAREA from the createQuestion.jsp
The problem is that it wites as XML for just the first set(ie Question, the 4 Choices and the Answer) I know this code does what it is doing but can anyone help me so i it will write it as XML for all the Questins i want to create
Thanx
prabhat kumar
Ranch Hand

Joined: Apr 11, 2001
Posts: 114
does all the question elements have the same name?
like parameter questionText??
then u can do something like this

hope it may help
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
Incidently, I think that an empty Text area will return an empty string, not a null.
Bill
midan myaa
Greenhorn

Joined: Nov 26, 2001
Posts: 8
Thanx prabhan but the parameters have different names as i want to be able to conert to XML every thing i enter into the textArea......This form is supposed to display a number of TextArea's for The Question , choices and answer, and i want to get the values for what ever number of set it is ie whether there are 2 Questions with 2 TextAreas for Question1 and 2 and 8 TextAreas for the choices
---------------
Question 1
----------------
Enter Question:
----------------
choice1
-----------------
choice2
---------------
choice3
-----------------
choice4
---------------
CorrectAnswer
-----------------
Question 2
----------------
Enter Question:
----------------
choice1
-----------------
choice2
---------------
choice3
-----------------
choice4
---------------
CorrectAnswer
--------------

<% int count = 1;
String number = request.getParameter("nOfq");
int qNumber = Integer.parseInt(number); %>
<form action="writeXML.jsp" method="POST">
<center>
<table bgcolor="silver" border="1" width="75%">
<tr align="center"><td><b>ENTER FILENAME:</b><br>
<textarea name="file" rows="1" cols="15"></textarea><br>
</td></tr>
<% for(int i=1;i<qNumber+1; i++) { %>
<tr align="center" bgcolor="#336699"><td><b>QUESTION <%= count %>: </b><br>
</td></tr>
<tr align="center"><td><b>ENTER QUESTION:</b><br>
<textarea name=<%="questionText"+i%> rows="5" cols="50"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 1:</b><br>
<textarea name=<%="choice_1"+i%> rows="2" cols="50"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 2:</b><br>
<textarea name=<%="choice_2"+i%> rows="2" cols="50"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 3:</b><br>
<textarea name=<%="choice_3"+i%> rows="2" cols="50"></textarea><br>
</td></tr>
<tr align="center"><td><b>CHOICE 4:</b><br>
<textarea name=<%="choice_4"+i%> rows="2" cols="50"></textarea><br><br><br>
</td></tr>
<tr align="center" bgcolor="#679995"><td><b>CORRECT ANSWER:</b><br>
<textarea name=<%="cAnswer"+i%> rows="2" cols="50"></textarea><br><br><br>
</td></tr>

<%count++; %>
<% } %>
<tr>
<td align="RIGHT"><input type="submit" name="next" value="NEXT">
</td></tr>
I hope you the the picture of what i wan tot do and you can help.......thank
 
 
subject: converting to XML file