header image
 

Why XML?

Preface

Well… XML has been around for quite a while, since 1998 to be precise. Yet, I still find quite a few folks in the soft. industry to not getting it. Why XML? What really made it such a revolution for the web we still relish till today. One comment I’ve heard recently made it over the top: “Let’s do it XML, because it is easy for the computer to parse”. Now, XML is possibly the single worst format for a computer to parse. FKS comma separated file is even more efficient. In case an efficiency of data format is the most sought for feature, nothing beats the binary. However, it also lacks any structure, and is commonly referred to as BLOB. Usually a description to the data, a.k.a. metadata, is maintained in the form of format header with fixed size and format in the header, or maybe footer, of the file/BLOB. Where the format of the header you can usually find from some documentation.

So far this is all common knowledge, all well known. XML is descriptive language and we can easily format structured data, keeping both data and metadata tight together. However, this alone is only part of what makes XML so great. To summarize, the reasons for a developer to consider XML goes as follow:

  • open standard specification
  • structured data
  • the XML stack (XML, XSD, XSLT)

The real power about XML comes from the third bullet point. That is the XML stack, or more precisely XML and the two other technologies, the schema definition language XSD and the XML transformation language XSLT. Unless, you are planning on using XML with any/both of the other two you might as well be much better using JSON. For being more efficient, less verbose, serving nicely the need of structured data alone.

The XML Stack

The XSD schema language is where one can describe a particular format for an XML file for his/her application. The benefit being that you can validate any XML against the XSD schema usually with one line of code. That feature alone makes classic SOAP Web Services still common today where any consumer of the service can validate its input data. However, combined that with the possibility to transform, that is to change the format of any XML from one to another, using XSLT and you end up with quite powerful stack.

The fact XML is standardized and it’s been around for more than a decade, gone through several revisions, makes it mature and quite well adopted. There are stable libs available for almost any platform you can think of.

Good Intermediate Format

Have you realised the power of the full XML stack, you can easily see that it helps you create CORRECT solutions to a common scenario. The scenario being: data shuffling and mapping. Which often encompass the bulk of most IT solutions out there.

It is easy to derive domain specific dialect. Making it, extremely easy to create open specifications. The most infamous example I can think of is HTML. Surprisingly many people are not aware that HTML is nothing more than specialized XML.

Although, the XML stack helps derive a correct solution, not necessary it is an efficient one.

Optimizing XML

One of the most common drawback of using XML boils down to the following points:

  • too verbose
  • size overhead
  • XSLTs are hard
  • XSDs are limited

I will cover only bullet point 2, size overhead. Since the rest I consider more or less, it is what it is, leave it or live with it. Still, the size overhead mostly has to do with the verbose expressions in XML.

There are plenty of things one can do to keep the size of XML to reasonable size. Starting from least intrusive, switching compression on HTTP transport level, to more intrusive like creating a lookup table of tags. Let me elaborate a bit more on the second option. The idea is to have on both end of communication, the same lookup table which maps verbose to HEX , and vice versa. Most cases will require less than 256 big dictionaries of tags, thus the 1byte size will suffice, in the range 00 – FF.

Keep in mind. I’ve not seen this second approach to mitigate hefty XML sizes, neither I’ve attempted myself doing so. I guess first approach is easy and good enough.

Structured Binary Data

In case performance is not mission critical and interoperability of binary data is of any concern, there is the public BSON binary format. Short for binary JSON. It is lightweight, traversable and efficient. http://bsonspec.org/

Another alternative is Google’s Protocl Buffers, http://code.google.com/p/protobuf/

Conclusions

To wrap it up, here is the moral of the story. Formatting the data is as important, if not even more, as the data itself. I’ve seen over and over again where developers makes the decision quickly on the fly. Often the wrong one!

Skype Virus Swipe Through Eastern Europe

In the past 2 weeks a huge wave of windows infection was observed on the Skype network. Mostly in the eastern Europe, Ukraine, Russia, Romania, … including Bulgaria.

It starts with a friendly message from someone from you contacts list, asking you to check out a photo of his/hers.

Here is a zip file of the file in question. MG0540250-JPG.scr

https://www.box.com/s/bapf8d0cy9qsm0wafehk

A Tribute to Aaron Swartz

[blog][twitter][latest@boingboing.net]

Aaron Swartz, at the age of my brother, found hanged to dead in his own NY apartment.

Only 26 and he had already accomplished more than any of us could do in a lifetime. His impact is remarkable of both his technical skills and the way he utilized his gift to steer a wider social impact through technology. See @wikipedia.

After a case like that there are way more questions than clear answers. Was his soon to come court appeal, the nasty prosecutor or the severe depression alone that he had openly admitted about? What really drove him to do it? Regardless of his reasons WE all ought a small tribute in his memory. PLEASE share a paper, book or anything you deem significant to spread wild!

Here is my humble contribution:

 The Art of Electronics 2nd ed. Horowitz and Hill pdf

https://dl.dropbox.com/u/13368335/The%20Art%20of%20Electronics%202nd%20ed.%20Horowitz%20and%20Hill.pdf

Tribute By Sharing PDF

See the on-going campaign to share a pdf for free download in his name. @storify.com

 Follow the Campaign on Twitter

#PDFtribute: https://twitter.com/search?q=%23aaronswartz

 Aftermath

It seems Mr Obama has granted Zwartz’s Wish, see here. (All Publicly Funded Research in US becomes FREE) Indeed some good news. Of course ‘publicly funded’ is debatable. Most serious research always involves both academia and industry. Who and How will draw the boundary still remains open IMHO.

Windows7 Asks For Registration, Again !


In case you have a pirated windows and it started asking for Licensing / Registration, yet again it must be due to a recent update you have applied, KB971033 !!!

Just about a year ago I got burned the first time and I had posted a tweet about it:

WARNING Windows update KB971033, attention to all pirates, avoid it if you intent to 
stay genuine and not detected :P  #windows #pirated Mon Dec 19 21:15:49 +0000 2011

Today I had the same problem on one of my parked win7 VM. Anyhow, here is what you need to do after :

Here are the steps to Unistall it:

  • Go to Control Panel\ System and Security \ Windows Update
  • Go to (down left) Installed Updates \ Windows , Find security update KB971033 and right click Uninstall.

It will show up on next check fo update, so you might as well hide it from there, here are the steps:

  • Go To Control Panel
  •   Click on Important Updates, Find security update KB971033 and right click Hide.

Don’t forget to reboot in order for the changes to have effect.

p.s. I am using pirated versions on VM with purely eprimental and evaluation purposes!

p.p.s. In case you have already lost your genuine windows privilages, you need to re-active your windows uisng the same tools as before or just google it!

Android Inspired AsyncTask

I’ve just released my first article on www.codeproject.com. It is one of those already matured platforms for coders to share knowledge and expertise. It has huge community and have bookmarked quite a lot of code gems through the years. Recently the site is going through some renovation and I was happy to find plenty of new features in addition to the polished new look&feel. So I decided it is about time I got involved.

Having spent plenty of time with Android and now with one successful project behind my back, I decided to introduce to the C# world one of the features I found most compelling to use. That is the AsyncTask and the use patter of anonymous classes. The intended purpose for the AsyncTask in the Android SDK is to easy decouple the GUI thread from the rest of your app. So that any time consuming task won’t stall the GUI keeping it responsive to the user at all times.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
new AsyncTask<int, int, string>(){
 
   Pre = delegate
   {
       return true;
   },

   Go = progress =>
   {
       this.progressBar1.Value = progress;
   },

   Do = (input, progress) =>
   {
           progrss.Report(1);
           Thread.Sleep(1000);
           progrss.Report(100);
           return “it took us 1 sec to finish”;
   },

   Post = (output, err) =>
   {
        //handle err
        //print output
   }

}.Execute(666);

I recommend you follow the full article at : codeproject . Still , let me clarify the use case of my C# AsyncTask. Similarly to the Java implementation the idea is to create an anonymous type with predefined 4 functions:

  • Pre : function as precondition, returning false abort further execution (call)
  • Do : the function which will be executed in the context of another thread
  • Go : the function responsible for reporting the task progress back to the GUI
  • Post : the function to be called upon finishing the task, processing further the output or report the exception err if any

Only the Pre function is optional, but I have already provided two implementations, with and without progress report capabilities. Also there are the 3 generic types, used respectively as the types for:

  • T1 : input type to Do
  • T2 : progress report type for Go
  • T3 : output return type, as return for Do function and argument to Post function

Same limitation, as to the original Java AsynTask, apply here too. Since we employ the threading pool, it is recommended to use AsynTask only for short lived background processes, e.g. downloading a relatively small ~MB image file from a remote server. Otherwise you risk starving the thread pool, resulting in any additional requests to be scheduled on a queue due to MAX limit imposed on the thread pool. This might result in unacceptable long deferring of execution for any new GUI interactions the user makes.

Hope you like it! GL HF!

Android Tutorials :: Tab Template

Previous Chapter : Android Tutorials :: Introduction
Next Chapter : TBA
Source GitHub : https://github.com/pip010/Android-Tutorials

Without much further adieu let’s start with the first of series of Android 2.3 Tutorials. I gave it the name basic tab template and can serve exactly that purpose. You can use it as a base app template to start any Android 2.2 and later Project. The tabular GUI is quite popular for apps targeting low Android versions, but it is getting obsolete in the latest iteration of the SDK where more visually appealing approaches are possible. Regardless of whether you plan to use it, I’m planning on bringing more to this first tutorial, so please stick around. As I already mentioned, my intent is not to provide step-by-step beginner tutorial, there are better places for the purpose: http://developer.android.com

First thing you should clearly comprehend is the notion of Activities in Android, along with Intents and Bundles, and how they fit together to bring a full app experience to the user. You can read the official docs here. The general idea is that you have only one Activity active at any given time and switching between activities is organized in a stack, you can read more here. I’ve included a helpful debug information for the life-cycle of an Activity (official Activty doc)(good article). I have included debug prints around so you can easily follow on each activity state change in the output pane inside Eclipse.

The Android SDK is a modern GUI framework, so in a manner common to others, has introduced templating (ala XAML) for all GUI related tasks. My advice is to rely on it as much as you can and keep any ‘programmable’ manipulation to minimum. It is still possible to do anything the XML templating engine does only with code, but I advice against, since you will find it very cumbersome and error-prone at the end.

One thing to realize is that you can cross reference xml documents using a ref tag. It will help you on keeping common patterns around, easy reusable between screens. You might easily find yourself getting overwhelmed by the mere task of keeping what is what in a sea of xml. For example you can pay attention that a raster resource might not necessarily be a png but yet another xml pointing to a png in addition to some extra conf parameters. Take a look at how I have implemented the header layout, files: .

1
2
3
4
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
   android:src="@drawable/header_bg"
   android:tileMode="repeat" />

I must give it to the Android designers that as far as addressing the pain caused by supporting multiple size and dpi screens they have done a good job. Although the official documentation might seem daunting at first, keep reading! Supporting Multiple Screens | Android Developers The general idea is that you have 4 type of dpi screens (ldpi,mdpi,hdpi,xdpia). You can always have a look at the default app icon, generated by Eclipse on New Android Project, and have these as reference for size ratio. You, or your designer, need to have a good understanding of the particularities in delivering sound resource files. Else you risk rendering your GUI at best ugly and at worst dysfunctional.

The tab control. After a quick view of the source you can see basically the definition of 2 activities for each tab we require. I found 5 tabs to be the acceptable maximum. In contrast to many Desktop GUI libraries, that way each tab is kept loose with no idea that it is part of something bigger, namely tabular container. A fine decoupling which gives a chance to change that at later stage, without being a slave to any direct dependence on the tab control as a result. One MainActivity is defined to host the tab control and each of the tabs is self contained in its own Activity, both layout and behavior. A bit on the dark side of the tab host is the incapability to defined the tab entirely in XML, or at least didn’t find any way to do it. As result I ended writing awkward feeling for loops to polish some of the look.

So far having diligently copy-pasted the sample code :)
You will have all the source code and resources in place. Even so, your app might give you such an error message in the log cat (the main log output window of ADK in Eclipse).

“No Launcher activity found!”
“The launch will only sync the application package on the device!”

We need to say explicitly to the SDK, which Activity to launch at app startup. After all they look all the same. Not really a main.c function out there either :P

A main ingredient part of any app is the metadata, basic configuration ;) , found in the file AndroidManifest.xml :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="net.ppetrov.android.template"
   android:versionCode="1"
   android:versionName="1.0">

    <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" />

    <application android:label="@string/app_name"
       android:icon="@drawable/ic_launcher"
       android:theme="@style/AppTheme">

    <activity
           android:name=".MainActivity"
           android:theme="@android:style/Theme.NoTitleBar"
           android:label="@string/app_name"
           >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
           android:name=".TabListActivity"
           android:label="@string/app_name"
           >
        </activity>
        <activity
           android:name=".TabInfoActivity"
           android:label="@string/app_name"
           >
        </activity>
     </application>  
</manifest>

We will be coming to this file often in the rest of the tutorials. It is the place where security permission are defined for your app. You specify the required dive resources you are planning to access. This information is used by Google Play to access the level of privacy concerns of your app than anything else. Once specified you should be OK.