×

Discussion Board

Results 1 to 15 of 15

Thread: XML comparison

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    XML comparison

    Hi all,

    I am designing an application in which I ask my user some set of questions. These questions are saved in the xml. The answer of the questions as well are saved in the xml and I want a J2ME code that can help me parse the xml and compare the users' answer against the correct one.

    What I mean is that I want my application to be able to say whether the user answers are correct or wrong based on the Answers in the J2ME. Can anyone help me on this? I am sure that someone would have done something similar to this. Thanks

  2. #2

  3. #3
    Nokia Developer Expert
    Join Date
    May 2007
    Location
    Mexico D.F
    Posts
    351

    Re: XML comparison

    Hello

    1. What phone are you using. If phone is capable you can use JSR172 XML parsing capabilities:

    http://www.forum.nokia.com/document/...72B4EEFE3.html

    2. If you want something that can work in any phone, then check this post

    http://wiki.forum.nokia.com/index.ph...ser_in_Java_ME
    :Ruben

  4. #4
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: XML comparison

    Hi olasamuel ,
    what you have to do is
    1.Parse your XML using any XML parsers KXML For reference refer the below links

    http://wiki.forum.nokia.com/index.ph...J2ME_with_kXML

    http://discussion.forum.nokia.com/fo...d.php?p=493910

    2. After parsing you will get the question and option .
    3. Present your question on the screen with your options . Depending upon the user choice you have to compare the user choice with the your correct answer.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: XML comparison

    Hi.

    Thanks for the reply. I actually understand the parsing aspect. What I want is that I want my application to be able to say whether the user answers to the question in my xml are correct or wrong based on the Answers in that I have defined in the xml. That is I want the code to be able to compare the two answers. That the ones in the xml and the ones that the user supplies.

  6. #6
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: XML comparison

    Hi ,

    After un-marshaling your xml you have to put the xml data in to one class like this
    class question
    {
    public String question;
    public String[] options;
    public String answer;
    }

    You will represent the question as one string item in the form and rest of the options in the chicegroup after that depending upon the user choice selected get the selected text and compare with your answer which is there in the class

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: XML comparison

    Quote Originally Posted by bhanuchandar.k View Post
    Hi ,

    After un-marshaling your xml you have to put the xml data in to one class like this
    class question
    {
    public String question;
    public String[] options;
    public String answer;
    }

    You will represent the question as one string item in the form and rest of the options in the chicegroup after that depending upon the user choice selected get the selected text and compare with your answer which is there in the class
    Hi Bhanu, thanks for the response. I actually did not see it at that time. Can you please give me the full skeleton code to do this as you have explained. It seems this will work if tried out. Thank you.

  8. #8
    Registered User
    Join Date
    Sep 2007
    Location
    Bangalore
    Posts
    868

    Re: XML comparison

    Hi,
    I don't know your xml structure . You have to wrap your xml things as an object that's it. Use KXML parser to parse the XML and create object with those values.

  9. #9
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Button on Alert

    Hi All,

    I developed an application that is fetching information from the xml. my back button is working well but I also make the system in such a way that if the user select an incorrect answer then a message should be displayed with alert and I put a button that will go back to the previous page on the alert so that the user can be able to select the correct answer but the back button is not working and the back button is working before. Can someone tells me what is it that I am doing wrong? Thank you.

  10. #10
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: XML comparison

    Hi,
    Please post ur code here even then anybody can help u. r u using form or canvas. well no matters but post ur code here.

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  11. #11
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: XML comparison

    Hi jitu_goldie

    This is the Code underneath.



    if (this.answer_Verify.equals(this.question_Node.getAnswer())) {


    // Correct! So set the alert string
    this.alert_String = "The selected answer is correct";
    Alert a = new Alert ("Answer", this.alert_String, null, AlertType.INFO);
    a.setTimeout(Alert.FOREVER);
    display.setCurrent(a);
    Alert a = new Alert ("Answer", this.alert_String, null, AlertType.INFO);
    display.setCurrent(a);
    }
    else {
    // Wrong! So set the alert string
    this.alert_String = "The selected answer is wrong. Select the back button to choose the correct answer before you proceed.";
    Alert a = new Alert ("Answer", this.alert_String, null, AlertType.INFO);
    a.setTimeout(Alert.FOREVER);
    a.addCommand(cmdBack);
    a.setCommandListener((CommandListener) this);
    Display.getDisplay(this).setCurrent(a);
    }

    So what is happening is that if the command button is added to form and when I click on it it will go back but because I add the command button on the alert and and I want the user to click on it to go back so that they can choose the correct answer. But when I click on it it will not go back. Can you tell me what I am doing wrong or the alternative way of doing this because I don't want the user to proceed without choosing the correct answer.

    Thanks

  12. #12
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: XML comparison

    hi,
    try this..

    Quote Originally Posted by olasamuel View Post
    Hi jitu_goldie

    This is the Code underneath.



    if (this.answer_Verify.equals(this.question_Node.getAnswer())) {


    // Correct! So set the alert string
    this.alert_String = "The selected answer is correct";
    Alert a = new Alert ("Answer", this.alert_String, null, AlertType.INFO);
    a.setTimeout(2000);
    display.setCurrent(a);
    }
    else {
    // Wrong! So set the alert string
    this.alert_String = "The selected answer is wrong. Select the back button to choose the correct answer before you proceed.";
    Alert a = new Alert ("Answer", this.alert_String, null, AlertType.INFO);
    a.setTimeout(2000);
    display.setCurrent(a);
    }
    no need to setcommandlistener to alert. just show it for 2seconds or if u want to setTimeout(Alert.forever) still no need to add any listener or command button.
    check and reply.

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  13. #13
    Registered User
    Join Date
    Oct 2008
    Posts
    21

    Re: XML comparison

    Hi Jitu_goldie


    Yeah I have tried this and it is working but what I want to do is that I want the message to remain there and so when the user clciks on the back button or done button it redirects the use back to the previous page and not the next page because I am reading the question from xml file. Can you help

  14. #14
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: XML comparison

    Hi ,
    please try this..

    // Correct! So set the alert string
    this.alert_String = "The selected answer is correct";
    Alert a = new Alert ("Answer", this.alert_String, null, AlertType.INFO);
    a.setTimeout(Alert.forever);
    display.setCurrent(a);
    }
    else {
    // Wrong! So set the alert string
    this.alert_String = "The selected answer is wrong. Select the back button to choose the correct answer before you proceed.";
    Alert a = new Alert ("Answer", this.alert_String, null, AlertType.INFO);
    a.setTimeout(Alert.forever);
    display.setCurrent(a);
    }

    no need to setany commandlistener and no need to add any extra command.when u set alert for forever mode then a default "Done" button is already appended. no need of extra coding. when user click on Done button then current is automatically set to ur previous screen.

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

  15. #15
    Super Contributor
    Join Date
    Sep 2008
    Location
    Noida, U.P.
    Posts
    1,330

    Thumbs up Re: XML comparison

    Hi,
    is ur problem is solved or not. Please do reply.

    thanks,
    jitu_goldie..
    thanks,
    jitu_goldie..

    KEEP TRYING..

Similar Threads

  1. Parsing xml data from the server using kxml2 in J2ME
    By dninsiima in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2010-03-26, 08:08
  2. Replies: 21
    Last Post: 2009-04-18, 12:00
  3. XML writing and Appending the Problem
    By talk2mishal in forum Mobile Java General
    Replies: 3
    Last Post: 2008-09-19, 19:24
  4. Need knowledge about XML and XML Parsing
    By 02060515 in forum Mobile Java General
    Replies: 1
    Last Post: 2008-07-07, 08:41

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×