Search This Blog

Wednesday 15 April 2020

XML and JSON are both designed to form a simple and standartized way of describing different kinds of hierarchical data structures and to facilitate their transportation and consumption in a standartized way. Nonetheless, there are few substantial differences that deserve attention. 
 

The major differences

Take a look at the following example:
JSON :





XML :




Clearly XML is somehow easier to understand for a human. That’s why it’s commonly used for configuration files (although lambdas and fluent APIs are recently emerging as a way of configuration). JSON, on ther other hand, is harder to read, but only from a human perspective. ​​
Aside from that, XML is also a markup language (as the name suggests) and is therefore suitable for document description – the hierarchical elements can also have attributes, which is not present in JSON. On ther other hand, JSON has a very concise syntax for defining lists of elements, which makes it preferrable for text format object serialization.
XML is also the usual choice of base when it comes to Domain Specific Languages
 

JSON and JavaScript

JSON's succinct syntax makes it very light and compact. It is also easier to parse from JavaScript, and that’s one of the main reasons it’s preferred for browser-based client-side applications (note that JSON stands for JavaScript Object Notation, it’s just natural). If you want to work with XML from JavaScript, you'll need to use an extra library for that. With JSON, you can just parse the message (let’s say with JSON.Parse() ) and work directly with js objects.

3 taire

details.java

package com.ann;




public class details {

String name,age,place;




public void setName(String name) {

this.name=name;

// TODO Auto-generated method stub




}



public void setAge(String age) {

this.age=age;

// TODO Auto-generated method stub




}



public void setPlace(String place) {

this.place=place;

// TODO Auto-generated method stub




}

public String getName(){

return name;



}
public String getAge(){

return age;





}

public String getPlace(){

return place;



}




}

2________________
package com.ann;
import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class databasehandler extends SQLiteOpenHelper {
 private static final String MYDB="mydb";
 private static final String MYTB="USER";

 public databasehandler(Context context) {
  super(context,MYDB, null, 32);
  // TODO Auto-generated constructor stub
 }
 public void onCreate(SQLiteDatabase db) {
  // TODO Auto-generated method stub
  db.execSQL("create table if not exists "+MYTB+"(name text,age text,qualification text,place text)");

 }
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  // TODO Auto-generated method stub
  db.execSQL("drop table if exists "+MYTB);
  onCreate(db);
 }
public void insert(details d) {
 SQLiteDatabase db=getWritableDatabase();
 ContentValues cv=new ContentValues();
 cv.put("name",d.getName());
 Log.v("name",d.getName());
 cv.put("age",d.getAge());
 Log.v("age",d.getAge());

 cv.put("place",d.getPlace());
 Log.v("place",d.getPlace());

    db.insert(MYTB,null,cv);
    Log.v("data","inserted");
}
public ArrayList<String> resultdata() {
 ArrayList<String> results=new ArrayList<String>();
 SQLiteDatabase db = this.getReadableDatabase();
 try {
  Cursor c=null;
   c = db.rawQuery("select * from "+MYTB, null);

  if (c!= null) {
  Log.v("cursor","notnull");
   c.moveToFirst();

   do {
     int cc=c.getCount();
     Log.v("cursor count",""+cc);
  
     String Name = c.getString(c.getColumnIndex("name"));
     Log.v("Name",Name);
     String Age = c.getString(c.getColumnIndex("age"));
     Log.v("Age",Age);
  
  
  
     String Place=c.getString(c.getColumnIndex("place"));
     Log.v("Place",Place);
  
     results.add("Name: " +Name+"\n Age : " +Age+"\n Place :"+Place);
     //results.add("dfrty");
     Log.v("Array",""+results);
    } while (c.moveToNext());
   }


 } catch (SQLiteException se) {
  Log.e(getClass().getSimpleName(),
    "Could not create or Open the database");
 }

 return results;
}

}   3------------------------------- package com.ann;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class DatabaseThreeActivity extends Activity {
 EditText ename,eage,eplace;
 String name,age,place;
 ListView lv;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ename=(EditText)findViewById(R.id.editText1);
        eage=(EditText)findViewById(R.id.editText2);
        eplace=(EditText)findViewById(R.id.editText3);
        lv=(ListView)findViewById(R.id.listView1);
    }
    public void submit(View v){
     name=ename.getText().toString();
     age=eage.getText().toString();
     place=eplace.getText().toString();
     details d=new details();
     d.setName(name);
     d.setAge(age);
     d.setPlace(place);
     databasehandler db=new databasehandler(this);
     db.insert(d);
        Toast.makeText(getApplicationContext(),"Details Submitted Successfully", Toast.LENGTH_LONG).show();
   
    }
    public void view(View v){
     databasehandler db=new databasehandler(getApplicationContext());
     ArrayList<String > result=new ArrayList<String>();
     result=db.resultdata();
     Log.v("reached",""+result);
   
     if (result.isEmpty()==true)
     //Log.v("after clear",""+result);
   
     {
      Toast.makeText(getApplicationContext(),"Database empty",Toast.LENGTH_LONG).show();
   
     }
     else
     {
      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, result);
      lv.setAdapter(adapter);
     }
    }
    public void updatate(View v){

 }
}





details.java

package com.ann;





public class details {
String name,age,place;





public void setName(String name) {
this.name=name;
// TODO Auto-generated method stub



}



public void setAge(String age) {
this.age=age;
// TODO Auto-generated method stub



}



public void setPlace(String place) {
this.place=place;
// TODO Auto-generated method stub



}

public String getName(){
return name;



}

public String getAge(){
return age;




}

public String getPlace(){
return place;



}



}