XML vs JSON

(by AXDS)

Both are very similar but used in different situations. Both are build around ‘key=value’ relationships.

‘JSON’ stands for ‘JavaScript Object Notation’.
‘XML’ stands for ‘extensible Markup Language’.

JSON:

  • (+) Fast, lightweight and compact.
  • (+) Same data types as Javascript.
  • (+) It’s documentation and design is simple and clear.
  • (-) Only supports a few data types.
  • (-) Sometimes syntax can be too simple.

XML:

  • (+) Can easily be split up and worked on my many different people.
  • (+) Can be used for all kinds of purposes. Very generalised.
  • (+) Support for namespaces.
  • (+) Can be manipulated and traversed using XPath/XQuery.
  • (-) More overhead than JSON. Resulting in a lot more words and space for the same information.

In general: JSON is better for lightweight scripting, XML is better for a secure ‘fixed’ markup.

Advertisements

Quickly create a ‘Website Viewer’ Android App using WebChromeClient.

(by AXDS)

Follow the bold words to speed up the tutorial 🙂

Create a new Android Studio Project. For this simple application a blank template will be a good choice.

Once it has all loaded replace the contents of the ‘mainActivity.xml’ file with:


<!--?xml version="1.0" encoding="utf-8"?--> <webview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent"></webview>

Add to the ‘AndroidManifest.xml’:

<uses-permission android:name="android.permission.INTERNET"> </uses-permission>

Replace nearly all the contents, don’t remove your package declaration of ‘mainActivity.java’ with:

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebPageLoader extends Activity
{
    final Activity activity = this;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
        setContentView(R.layout.mainActivity);
        WebView webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setJavaScriptEnabled(true);

        webView.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress)
            {
                activity.setTitle("Loading...");
                activity.setProgress(progress * 100);

                if(progress == 100)
                    activity.setTitle(R.string.app_name);
            }
        });

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });

        webView.loadUrl("http://www.informaticskb.wordpress.com");
    }
}

Connect your phone and run the application!