java - I want to parse xml file to jsp, -


i have xml file containing questions, choices , answer. doing project online test. show questions xml, choices questions xml(radio buttons), next button show next question , choices. problem is, if looping choices node, choices printing in same line instead of printing in separate line. please me out. find xml file below:

<data>   <question id="1">     <qtext>what kb stand for?</qtext>     <choices>       <choice>kilo bits</choice>       <choice>key board</choice>       <choice>kilo bytes</choice>       <choice>none</choice>     </choices>     <answer>3</answer>   </question>   <question id="2">     <qtext>cpu stands for</qtext>     <choices>       <choice>central processing unit</choice>       <choice>central power unit</choice>       <choice>core processing unit</choice>       <choice>core power unit</choice>     </choices>     <answer>1</answer>   </question>   <question id="3">     <qtext>1 kb equals</qtext>     <choices>       <choice>1000 bytes</choice>       <choice>1024 bytes</choice>       <choice>1000 bits</choice>       <choice>1024 bits</choice>       <choice>nothing</choice>     </choices>     <answer>2</answer>   </question>   <question id="4">     <qtext>ram </qtext>     <choices>       <choice>random access modifier</choice>       <choice>primary memory</choice>       <choice>secondary memory</choice>       <choice>read , modify</choice>     </choices>     <answer>2</answer>   </question>   <question id="5">     <qtext>hard disk </qtext>     <choices>       <choice>hard break</choice>       <choice>primary memory storage</choice>       <choice>temporary memory storage</choice>       <choice>secondary memory storage</choice>     </choices>     <answer>4</answer>   </question>   <question id="6">     <qtext>computer monitor used </qtext>     <choices>       <choice>to monitor activities</choice>       <choice>to control computer</choice>       <choice>as display unit</choice>       <choice>none</choice>     </choices>     <answer>3</answer>   </question>   <question id="7">     <qtext>xml stands for</qtext>     <choices>       <choice>extended markup language</choice>       <choice>extended model language</choice>       <choice>extensible markup language</choice>       <choice>extensible model language</choice>     </choices>     <answer>3</answer>   </question>   <question id="8">     <qtext>asp stands for</qtext>     <choices>       <choice>active server page</choice>       <choice>application service provision</choice>       <choice>as possible</choice>       <choice>all</choice>     </choices>     <answer>1</answer>   </question> </data> 

jsp

<%@page import="java.io.file"%> <%@page import="java.io.inputstreamreader"%> <%@page import="java.net.url"%> <%@page import="java.io.filereader"%> <%@page import="java.io.bufferedreader"%> <%@ page contenttype="text/html; charset=utf-8" language="java" import="javax.xml.parsers.documentbuilderfactory, javax.xml.parsers.documentbuilder,org.w3c.dom.*, java.io.*" errorpage=""%> <html> <head></head> <body> <% documentbuilderfactory dbf = documentbuilderfactory.newinstance(); documentbuilder db = dbf.newdocumentbuilder(); document doc = db.parse(application.getrealpath("/")+"/qbank.xml"); nodelist question = doc.getelementsbytagname("question");  (int temp = 0; temp < question.getlength(); temp++) {     node qnode = question.item(temp);     if (qnode.getnodetype() == node.element_node) {         element qelement = (element) qnode;%>         <label><%out.println("question : "+ qelement.getelementsbytagname("qtext").item(0).gettextcontent()+"<br/>");%></label>         <%         nodelist choice=doc.getelementsbytagname("choice");         for(int i=0;i<choice.getlength();i++){              node cnode= choice.item(0);             if (cnode.getnodetype() == node.element_node) {                 element celement = (element) cnode;                 out.println("choices : "+ qelement.getelementsbytagname("choice").item(0).gettextcontent()+"<br/>");             }                                }     }            } %> </body> </html> 


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -