0

I want to use XML to store data for an assignment . In this Java assignment I'll get data from the user in form of lines in a file below

INSERT INTO student(id,name,family,isMale) VALUES (10,null,”Maryam”, “Hasani”, false)
CREATE TABLE student(id:integer, gpa:decimal, name:string, family:string,isMale:Boolean)
INSERT INTO student(id,gpa,name,family,isMale) VALUES (50,”Ali”, “Hasani”, true)
SELECT id, name FROM student WHERE id=0
so on ..

and after reading the file and processing them ,the program will generate logs about the outcome of the input files .like examples below:

ERROR: Invalid data type for value of column family
ERROR: Invalid table name st

my question is about the processing data and storing them. I shouldn't use the usual tools for database like sql as the assignment wants me to somehow do what sql does without sql. I've chosen XML for this job so after reading the input ;program will parse the data of each line using regex and then store the data in a third file (between output and input files) using XML to have a more organized data.

<student id  = "1" >
   <active>True</active>
   <gpa> 12 </gpa>
   <name> ali </name>
   <family>alavi</name>
   <isMale>True</isMale>
</student>

is XML a good choice for what I want?

if it is what parts of XML should I learn for this task as there seems to be a lot to learn?

what things should I note in working with XML and coding the program working with XML file ?

if XML is not suited for this task what are the alternatives ?especially the ones who are easier to learn and work with for someone like me(look at p.s).

p.s:I'm quite new to java and programming as whole

1 Answer 1

1

Use XML if your data is a lot more nested and complicated than this.

In this particular case I would suggest using JSON (if you cannot use relational databases as you have mentioned yourself).

As for learning JSON it is very simple. There is nothing to it but learning the structure. Once you got the structure down you can pretty much create any type of data you want.

Here are some references to get started with JSON:

1) http://www.w3schools.com/json/

2) http://json.org/

3) https://code.google.com/p/json-simple/wiki/EncodingExamples

2
  • thank you but is it easy to learn and work with ? and what are some good sources to learn it ?
    – Vicarious
    Mar 31, 2015 at 21:25
  • @Vicarious I edited my original answer and put some references there for you to get started. W3Schools will pretty much do for getting started. It simply lays out all you need so start with that! Mar 31, 2015 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.