Quiz app in jsp using xml as datasource

Hi if one wants to set up a simple application like a quiz app that stores all its question in an xml file.
The basic structure is like a java class reading from the xml using DOM/SAX then writing the info in the bean then getting that info in a jsp file.
But i am having some problem with the code.
First problem is how do i read a set of records from the xml file to the bean and then transfer it to the jsp page. I am using a simple java bean no EJB's
Any help appreciated

Does the javabean represent one question or does it represent all the questions (so - do you have QuestionBean or QuestionsBean)?
For the sake of discussion, let's say that you have a QuestionBean - it represents one question; (it may also contain answers, too?)
Let's also create an object that will hold the questions. How about calling this QuizBean?
Your Parser.java would use jdom to read in the xml file. For each question node it finds, it creates a QuestionBean and sets the properties.
hi steve until here its quite clear...
but why do we need to create another quiz bean, cant we read each time from the xml file, yes the xml file has questions and answers.
suppose there is a next button in the jsp page and each time its hit this happens
xml >> parser.jsp ( fetches a question with answer ) >> bean.java >> jsp
sorry steve i am kind of newbie in jsp, i have always used microsoft technologies, so ..... :)
questions.xml
<?xml version="1.0" encoding="UTF-8"?>
<Subject>
          <Topic Name="science">
          <Questions>
               <Ques>What is the color of the sky?</Ques>
               <wrong>green</wrong>
               <wrong>yellow</wrong>
               <wrong>brown</wrong>
               <correct>blue</correct>
          </Questions>
          <Questions>
               <Ques>what is xml?</Ques>
               <wrong>i dont know</wrong>
               <wrong>we dont know</wrong>
               <wrong>you dont know!!!</wrong>
               <correct>use google :)</correct>
          </Questions>
          <Questions>
               <Ques>where is delhi ?</Ques>
               <wrong>bombay</wrong>
               <wrong>pakistan LOL</wrong>
               <wrong>usa</wrong>
               <correct>near noida</correct>
          </Questions>
     </Topic>
     </Subject>

Similar Messages

  • CrystalReports Subreports Demo Using XML As DataSource , Java As Tool

    Hello,
        Im New to CrystalReports.Can any one send me (or) explain me Regarding "CrystalReports Subreports Demo Using XML As DataSource , Java As Tool" .
    Thanks,
    RadhaKrishna K

    ok

  • Problem in impelementing tree in jsp using XML

    I am trying to impelemnt "treeview.htc" to impelement tree structure in my jsp page.I am using XML file to get the elements for treenodes.Now My Problem:
    Basically i have one ASP page with me, and there they have done all this things.But when i try to impelement the same thing in JSP it is thrwing me error.
    <b>Error: It is unable to detect the namespace i have mentioned in :>
    IT is not able to detect the "TVNS" namespace..Hence showing error while saving the jsp file</b>
    <code>
    <?XML:NAMESPACE PREFIX=TVNS />
    <?IMPORT NAMESPACE=TVNS IMPLEMENTATION="C:/XMLTREE/treeview.htc" />
    <tvns:treeview id="ctlFilter_TreeFilter" class="clsTreeView"
    defaultStyle="font:normal normal normal 8pt Tahoma;" selectedNodeIndex="0" HelperID="__ctlFilter_TreeFilter_State__" systemImagesPath="C:/XMLTREE/images"
    onexpand="javascript: if (this.clickedNodeIndex != null) this.queueEvent('onexpand', this.clickedNodeIndex)" oncollapse="javascript: if (this.clickedNodeIndex != null) this.queueEvent('oncollapse', this.clickedNodeIndex)"
    oncheck="javascript: if (this.clickedNodeIndex != null) this.queueEvent('oncheck', this.clickedNodeIndex)" onselectedindexchange="javascript: if (event.oldTreeNodeIndex != event.newTreeNodeIndex) this.queueEvent('onselectedindexchange', event.oldTreeNodeIndex + ',' + event.newTreeNodeIndex)" style="height:100%;width:100%;">
         <tvns:treenode Type="And" Expanded="True" Selected="true">
              And<tvns:treenode Type="Property">
                   Buyer Name = "Abukar Hagi, Abdirashid"
              </tvns:treenode><tvns:treenode Type="Property">
                   Buyer Name > "Abukar Hagi, Abdirashid"
              </tvns:treenode><tvns:treenode Type="Property">
                   Buyer Name <= "Abukar Hagi, Abdirashid"
              </tvns:treenode>
         </tvns:treenode>
    </tvns:treeview>
    </code>
    Please help me out .its very urgent.
    Thanks in advance.

    Have you actually been able to get this to work? I tried some of the demos from the MS site and running the html file with the treeview.htc just sends my browser into a state of loading with nothing happening!?!
    This is a webcontrols component which is rather MS specific. As for finding the namespace, are you accessing this page locally or remotely? the namespace location, if run from a JSP, will resolve the C: drive to the one the web browser is running in not your server.
    If you have your htc file in the same dir as the jsp your running, then putting just "treeview.htc" as the namespace whould be fine or add the context path like so:IMPLEMENTATION="<%=request.getContextPath()%>/treeview.htc"Let me know if you actually get this running without a web server. Otherwise it may be the .Net server that renders the page.
    Anthony

  • When to use XML file Datasource

    Hi,
    I would like to know under what scenario we have to use the XML file as a datasource?
    Is it possibe to extract data from a email.
    The client is getting data in email everyday and is it possible to upload this data directly from the email.
    or do i have to convert this data in the form of  a .csv flat file and upload.
    please give an idea if i can use the XML file upload facility provided in BI, whether i can use this in my
    scenario.
    regards,
    man

    Hello Man,
    Please see this doc for sending XML data to BW
    [How to Send XML Data to BW|https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/21d8aa90-0201-0010-5e83-a3798b9a5ee0]
    [How to… Push Data into BW from XI|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/18dfe590-0201-0010-6b8b-d21dfa9929c9]
    [SAP BW Data Retrieval|http://www.sap-press.de/download/dateien/939/sappress_sap_bw_data_retrieval.pdf]
    For Transfering data using XML see this SAP Help Page [SOAP-Based Transfer of Data |http://help.sap.com/saphelp_nw04/helpdata/en/fd/8012403dbedd5fe10000000a155106/content.htm]
    Thanks
    Chandran

  • Using XML as datasource of JList

    Hi,
    I new with java and trying to figure out how to create guis with netbeans 5.5.
    I have dragged and dropped a jlist but I couldn't find out how to put a datasource on it. There were ways to use a database (create a connection then connect to it) but I want to use an xml file as datasource instead of a database.
    How can I do it? Both drag and drop options and writing my own code is appreciated. If you can point me to a tutorial that is also welcome.
    Thank you for your time
    Roy Simkes

    1. Parse the xml
    2. Add the nodes from the parsed xml into any of the following
    2.1 Array of objects (Object[])
    2.2 Vector
    2.3 ListModel (preferred)
    3. Create the JList using the appropriate constructor.
    voila ...
    Hope this helps,
    PS.

  • Using XML as datasource.

    Post Author: gronkette
    CA Forum: Data Connectivity and SQL
    With CRXI I'm able to connect to a "specific" XML file - the "folder" option does not work.  Anyway, when I view the data fields I only see the first 2 columns:
    Asset Name  Asset Value 1
    I should see:  Asset Name, Asset Value 1, Asset Value 2, Asset Value 3 ..........Asset Value 24
    I've been usint the Database Expert > ODBC RDO, it's also the only way I've been able to load any XML files.
    thanks!

    1. Parse the xml
    2. Add the nodes from the parsed xml into any of the following
    2.1 Array of objects (Object[])
    2.2 Vector
    2.3 ListModel (preferred)
    3. Create the JList using the appropriate constructor.
    voila ...
    Hope this helps,
    PS.

  • Would my java app benefit from using XML?

    Hi, I'm trying to plan my first Java project, and I still don't know which is the right approach to follow.
    My application should provide add, delete, search, and modify capabilities against a list of records (couples of namesurname and telephone number) stored in a file.
    My first idea was to organize these information is a text file, where a comma divides namesurname from telephone, i.e.
    foo,12345
    bar,18347
    etc..
    This requires to manually write add/delete/search/modify methods by hand, but still worst, changing a record requires that the whole file is written (imagine to write a file with 10000 records just because one record only has been modified..).
    So my second "idea" was to use an XML file where organize the data. In this way add/delete/search/modify are provided by the API.
    At this point I have two questions: do you suggest to use the DOM API or SAX? Then, a change to a record, would require to save the whole file or just the change is saved?
    Hope you want to help, thanks!

    Hi Paolo,
    In general I prefer using higher level APIs like JAXB and JAXB.
    DOM would enable you to read the XML into a DOM Document object from where you can easily CRUD entries (use XPath to search for them first). This approach means that you don't need to write a DirectoryEntry class (see below) or manage the surrounding data structure, however its not particually efficient on memory or CPU. Its also not good practice from an OO point of view. Even then the Document object only exists in memory and the API doesn't give you much help saving the Document object or converting it back to text (XSL is about the simplest way to do this - toString() isn't guaranteed to work). Therefore changing a record would still require a full save.
    SAX is only useful for parsing XML documents into java objects (like the DirectoryEntry class).
    For your example I would read the data from a CSV (using the ostermiller library - see google) file into a data structure (e.g. ArrayList, HashMap, HashSet etc) of DirectoryEntry objects
    public class DirectoryEntry
       private String firstName;
       private String lastName;
       private String phoneNumber;
       public X(String firstName, lastName, phoneNumber)
       public String getFirstName()
       etc...
    }Then write routines to search and CRUD (Create, Retrieve, Update, Delete) directory entries in the data structure. If you're writing this purely for experience I wouldn't bother about saving updates to file after each operation - in the "real world" you would use a database so the experience wouldn't be worth much. If required you could add an extra routine for saving all the information to disk upon an explicit user command - and yes, this means writing a complete copy of the file each time (unless you use a clever file format and low level API for random access).

  • Designing the structure of jsp pages using xml

    how can i design the structure of the jsp using xml file?

    The structure of the JSP? I don't know what that means. Perhaps you can explain why you thought using XML for that would be a good idea, that might help us comprehend the question.

  • Reading jsp  tag using xml

    Hello friends,
    I have a problem.
    I have a jsp page in that i have to find a particular tags. using xml
    but i dont know about dtd and. please help me
    example.
    <input type ="text" value= "ss">
    now i want to find the above tag using xml
    so please give me the logic how to find a tag in jsp using xml. ?
    please help me.

    A JSP is for displaying data. Read after me:D-I-S-P-L-A-Y-I-N-G. It has no business parsing or
    reading or calculating anything.
    I don't know what the OP want's to do. Maybe he
    want's to write a application which replaces some
    html tags in JSP files.
    His post can also be interpreted that he want's to
    use JavaScript (DOM)) to find any particular tag.Hello,
    my problem is in our application some programmers have written hardcode in <intput tag> like <input type name ="hardcode" instead taking values from database dictonary.
    so now i have to find the line no. where they have written the hard code.
    for that my pl is asked to solve using dom.
    for that i need to find the html tags.
    but i m not able to do that.
    can u suggest me.
    Regards

  • How to display the data in XML files into JSP using Jdeveloper.

    Hi All,
    I have two XML files one XML file has the view names and the other has the table names of a particular views, how to display the data in JSP using JDeveloper where when i click a particular view the list of tables of that particular view from XML file two should be displayed in JSP Page.
    Are there any reference documents, regarding the above process please can anyone guide through how to do it.

    Let the servlet ask your business tier to provide the data, then stuff it into beans, and pack those into the Session instance. Then forward the request to the JSP, let the JSP get those beans and display them.

  • XML as DataSource for JSF app

    I am using xml files as the data for a JSF app. I know how to use dataproviders attached to databases in order to display and update data to and from the jsf page. Is there a simple way to do this with XML as the data source?

    Let me just add I would like to be able to do CRUD on the xml

  • How to create Entity objects using xml as a datasource

    Hi All,
    How to create EO(ADF Business components) using XML as a datasource instead of database tables..Pls do reply..Its an urgent requirement
    Thanks in Advance
    Edited by: 1000899 on Apr 25, 2013 12:01 AM
    Edited by: 1000899 on Apr 25, 2013 12:02 AM

    There is nothing 'urgent' in this forum. We are all volunteers spending our spare time helping out other users. If you have an urgent matter, you have to open an SR with sopport.oracle.com
    If it's urgent, then why don't you provide information needed to answer the question.
    Which jdev version do you use?
    What is the use case?
    To answer your question: A look into the docs http://docs.oracle.com/cd/E35521_01/web.111230/e16182/bcadvvo.htm#sm0341 and http://docs.oracle.com/cd/E35521_01/web.111230/e16182/bcadvvo.htm#sm0338 holds the answer to it.
    Timo

  • Publish app that uses XML file.

    Hi, I want to create an App which uses XML file as a data source. I want that XML file is online file on my server downloaded in first use, and looking for changes every time user want to do this, so i have a legal question if apple can release my app in AppStore or they can block it?

    Thanks,
    I have legal right, this is my XML file on my server.
    My main concern is that changing XML in fact i may change entire app. And this make me think apple would not like it. So my question is: maybe someone had similar experience.

  • Crystal report from JSP using the JRC

    Hi, I am trying to call crystal report from JSP using the JRC.
    But i am getting the Error as 'Logon Failed'. my web.xml entry is
    <env-entry>
    <env-entry-name>jdbc/Test</env-entry-name>
    <env-entry-value>!oracle.jdbc.driver.OracleDriver!jdbc:oracle:thin:{userid}/{password}@//10.0.0.1:1521/TestDB</env-entry-value>
    <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    i am setting the userid and password in the code. Please see the below code for your reference. Please help me to solve the issue.
    <%@ page language="java" contentType="text/html;charset=UTF-8"%>
    <%@ page import="com.crystaldecisions.report.web.viewer.CrystalReportViewer"%>
    <%@ page import="com.crystaldecisions.sdk.occa.report.data.*"%>
    <%@ page import="com.crystaldecisions.reports.reportengineinterface.JPEReportSourceFactory" %>
    <%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSourceFactory2" %>
    <%@ page import="com.crystaldecisions.sdk.occa.report.reportsource.IReportSource" %>
    <%@ page import="com.crystaldecisions.reports.reportengineinterface.JPEReportSource" %>
    <html>
    <head>
    <title>Crystal Report with Database Logon information</title> </head>
    <body bgcolor="#ffffff">
    <%
    try
    String report = "/TEMPLATE.rpt";
    IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();
    JPEReportSource reportSource = (JPEReportSource) rptSrcFactory.createReportSource(report, request.getLocale());
    CrystalReportViewer viewer = new CrystalReportViewer();
    viewer.setReportSource(reportSource);
    viewer.setHasRefreshButton(true);
    IConnectionInfo newConnInfo = new ConnectionInfo();
    newConnInfo.setUserName("TEST");
    newConnInfo.setPassword("TEST");
    ConnectionInfos newConnInfos = new ConnectionInfos();
    newConnInfos.add(newConnInfo);
    viewer.setDatabaseLogonInfos(newConnInfos);
    viewer.setEnableLogonPrompt(false);
    viewer.setOwnPage(true);
    viewer.setOwnForm(true);
    out.println("Connection Information: "+viewer.getDatabaseLogonInfos().getConnectionInfo(0).getAttributes().toString());
    viewer.processHttpRequest(request, response, getServletConfig().getServletContext(),null);
    viewer.dispose();
    catch(Exception e)
    throw new JspException( e);
    %>
    </body>
    </html>

    I never really had much luck with this approach.
    Mind you I was using Crystal Reports 10, and as far as I recall it didn't allow setting/changing of database at this level.
    Things to check
    - can you create a database connection on your page with this URL/username/password?
    - what server are you using? Tomcat? WebLogic?
    I found this in your other post:
    Connection Information: {Server Name=ee6rpt, Connection String=DSN=s(ee6rpt);User ID=s(ee62test);Password=;UseDSNProperties=b(false), Database Name=, Database DLL=crdb_odbc.dll}That would indicate it is using odbc to connect to the database (crdb_odbc.dll). ODBC is a bad idea with java.
    The way I have got it to work for me (after much trial and error) was to in Crystal Reports to connect using the Oracle Driver, and specifying a tnsname - eg define REPORT_DS in tnsnames.ora.
    When running through the JRC, it looked for a JNDI datasource under that same name "REPORT_DS".
    Don't know if that will help you or not.
    Good luck,
    evnafets

  • Using XQSL w/Datasource : ClassCastException

    I'm attempting to use XSQL in a Websphere 5.1 test server (WSAD) and I am getting this error:
    Oracle XML Developers Kit 10.1.0.2.0 - Production
    XML-25017: Unexpected Error Occurred
    java.lang.ClassCastException: com.ibm.ejs.cm.proxy.OracleCallableStatementProxy
    at oracle.xml.xsql.actions.XSQLRefCursorFunctionHandler.handleAction(XSQLRefCursorFunctionHandler.java:102)
    The datasource in question is setup correctly since it works as implemented in the web app. XSQL appears setup correctly because it works with using XSQLConnectionManagerFactoryImpl and <connectiondefs>, and it also works using a AS400JDBCDriver Datasource with XSQLOracleDatasourceConnectionManager.
    I'm using classes12.jar (and have tried it with the latest 3 versions). I'm using jdbc:oracle:thin with oracle.jdbc.pool.OracleConnectionPoolDataSource.
    Finally, (not sure if this helps) when I decompile XSQLRefCursorFunctionHandler, line 102 appears to bomb here (see below), so I added a "date-format" attribute and value just for funzzies, without change in result:
    if(s1 != null && !s1.equals(""))
    oraclexmlquery.setDateFormat(s1);
    boolean flag1 = s9 != null
    && (s9.equalsIgnoreCase("yes")
    || s9.equalsIgnoreCase("y"));
    I'd would greatly appreciate some help.
    Thanks in advance!
    Monte

    One possible reason is that i am using javax.sql.datasource in the source code but the DataSource has been defined with "com.evermind.sql.DriverManagerDataSource" throwing the classcast exception.
    any idea in which jar the "com.evermind.sql.DriverManagerDataSource" class can be found ?

Maybe you are looking for