Hi Guys ,
how can i parse java script.I have a script as follows

test.AddQuestion( new Question ("com.scorm.golfsamples.interactions.etiquette_1",
                                "When another player is attempting a shot, it is best to stand:", 
                                new Array("On top of his ball", "Directly in his line of fire", "Out of the player's line of sight"),
                                "Out of the player's line of sight",
test.AddQuestion( new Question ("com.scorm.golfsamples.interactions.etiquette_2",
                                "Generally sand trap rakes should be left outside of the hazard",
test.AddQuestion( new Question ("com.scorm.golfsamples.interactions.etiquette_3",
                                "The player with the best score on previous hole tees off:", 
                                new Array("First", "Last", "With a putter"),

if you look at the code it has question with options and answer in teh end .I want ot extract question and answer part of this script.Can anyone help me with this .Thanks

This is probably the wrong answer, but if you have this kicking around, could you not just write a "Question" class and an Extractor class that can "AddQuestion", then feed this stuff into an instance of Extractor that you've named "test"?

It looks to me like the jvm will parse this handily - why should you go to the trouble?

commented: Sounds like a good idea to me! +13

Is this a one time job or will there more input scripts that you want to parse later?

If one time, do as suggested above.

If more than once, write a program to wrap the scripts in a compileable program to do what was suggested and use the javac class to compile it into a class file that you can load and execute as suggested above.

this will be done multiple times ina day and may be million times in year.

So about 3000 times in a day, or thereabouts? Okay, you'll want to automate the process, then. That'll be interesting. I'd be inclined to set up a drop folder for the javascript files, and have your program grab any files from that folder, do its thing to them, and leave them in a "completed" folder, possibly sub-foldered by date.
This actually could require a little work. Let us know how you end up doing it.

Sorry!but thats what i want to know.How to accomplish this. all i need to know is how to extract text from java script.

Okay, before you do it a million times, you'll have to do it once, right? So let's start with getting one file, and try to do it in a way that will scale up nicely.
We've got an approach to start with, which some smart people have agreed is likely to be a good way to go. So let's begin there. Do you follow what I suggested in my first response?

Let me add, this is not going to be a trivial problem to solve. It will probably require some advanced techniques - if you're a beginner, this might not be the best place to start. For a start, are you familiar with file i/o methods? Can you open a file, explore its contents, and put some of the contents into a new file?

Are all the java program segments the same as what you posted?
They all call the addQuestion of the object referenced by test.
And there are no other references in the code segments that would cause a compile error,
except for the QUESTION_xxx symbols which look like finals of some kind.

Hi ,
i know how to open a file, I know how to use regex function, What i want to know is how can i read this text in a way that i should be able to extract all questions and store them in array and same goes for the answers.

Okay, what do you think of my earlier suggestion? Does it make sense to you?

I thought your idea was fantastic!!! Definitely the way to go. I took about an hour and wrote a prototype to validate the idea. Worked like a charm. Definitely scalable.
Let javac do the parsing and have the addQuestion() method call feed you the parsed results.

Glad you liked it, Norm. What about you, Sadhawan? You're the one who needs to parse the stuff.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.