Visualizzazione post con etichetta tutorial. Mostra tutti i post
Visualizzazione post con etichetta tutorial. Mostra tutti i post

martedì 19 marzo 2013


HABEMUS MBC!


 HOW TO VALIDATE XML FROM XSD WITH NOTEPAD++ AND XMLTOOLS PLUGIN
-
COME VALIDARE UN XML DA UN XSD USANDO NOTEPAD++ E IL PLUGIN XMLTOOLS


Hi guys,

this evening I wanna only suggest you a quick trick for validating an XML from his XSD.

How you all know, XML is a markup language (it means eXtensible Markup Language), that means you can create your own structure of document ONLY defining the properties of the elements inside, and every "translator" can receive informations from it.
A raw method for translating XML docs is creating an XML parser by yourself: if you know the structure of the document, you can get all the infos you need.

But what if, for example, you expect an integer and you get a string instead? You get an "unbelievable" parsing error in every programming language known and unknown (at least as far as I know).

So what you need? A structured document containing the rules about every element of your xml. How it's long, which type it is, the chars admitted too!!!
In one word, you need an XSD document (Xml Schema Definition). You can create your own, by your hand or using a thousand tools, but in most cases, you'll create an XML and you'll need to validate it according to an existing XSD received by a third party, a customer or a web service.

At this point you have two choices:

  1. Create a parser that receive an XML and ITS XSD, and then check all XML elements according the rules included in XSD (that's a very good programming exercise about XML-XSD, but it needs time and it may not be helpful if you hurry);
  2. Find an existing tool or library that does it;
Because I'm always in a hurry, I've chosen the second.Googling for the web, I found that my favourite editor, Notepad++, has what I was looking for: a golden plugin that validate an XML from an XSD. His name is, with a lot of imagination, XML Tools.

Let's see how to get it.

If you have not, download Notepad++ from here. It's free. 
And now that the force is strong with you, install and open it.
Go in "Plugins -> Plugin Manager -> Show Plugin Manager", then scroll through the list and check "XML Tools". Click on install and wait a few seconds.
1.1 How to install XML Tools
Now you got XML Tools.
But how to use it? It's very quick and simple.
With this plugin you can do a lot of useful thing, like formatting your text using the "Pretty" functions, or "Enable auto-validation" at every saving...
However, first open your XSD document. Then go "Plugins -> XML Tools -> Validate now".

Doing that you can check that your XSD is well-formed. For example, a common error is "XML Parsing error at line XX: Extra content at the end of the document".
Then you go to the end of the document, and nothing: it's all ok... What the hell's happening?
Simple: you get THIS error:

1.2 XML Parsing error at line XX: Extra content at the end of the document
You see them? You have HORRIBLY KILLED two space blancks!
Correct them, and this error will disappear... Thank me: I've saved you an hour during a full emergency "deadline on arrival"!

Ok, now go on your XML. Click on "Validate now". If your XML can't reach the associated XSD, a prompt appear, and you must select the directory of the XSD. After that validate again: another dialog appears, and
  1. can tell you that the validation is successful;
  2. that you have an error, indicating the relative ELEMENT, the VALUE and the XSD RULE, in order to allow the immediate identification of the error (they could also indicate the line number, but that's okay...)
1.3 Showing the error 


Note that the dialog box may also not appear: but it happens ONLY when XML is validated.o
That's all. Bye!


venerdì 15 marzo 2013


HABEMUS MBC!


 HOW TO CREATE AN ANDROID PROJECT USING GOOGLE MAPS API V2
-
COME CREARE UN PROGETTO ANDROID USANDO LE GOOGLE MAPS API V2

Aaaaaaall right, folks.
This evening I decide to explain you how to create an Android Project using Google Maps API V2.
First of all let me say that using V2 API
  1. it's a bit harder then V1 API, cause the libs for Maps are not contained in a .jar archive, but must be imported as a project library;
  2. make your life easier while you programming your app's activities. The listeners have been optimezed, most of the logic has already been implemented, so the benefits are greater difficulties.
Let's start.

So you're already an Android Dev, you paid your life-long-fee, and you get your API KEY from your API CONSOLE.

Then open Eclipse, click on "Android SDK Manager", then check that "Google play services" is installed. If not, download it

1.1 How to check if you have Google Play Services
Ok, now you've got all you need to use maps.

- Create a new Android Project,

call it "Gennarino", or "Francis_FROM_Coppola" if you like it. Or "PrjBase" if you're indescribably boring. 

- Then go to your "androidManifest.xml" 

and add the highlighted strings, like in the pics below...

1.2 androidManifest.xml - ADDING PERMISSIONS AND OTHER SETTINGS

1.3 androidManifest.xml  - ADDING API KEY

... from which all of you can understand how boring I am... ;)
By the way, let's stop a moment for explaining.
  • <permission       
    android:name="prjbase.main.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />
    It means that you ask to your OS the permission for receiving MAPS, using a "signature" (your API KEY);
  •  <uses-feature     android:glEsVersion="0x00020000"
  •      android:required="true" />

  • That's indicates the openGL ES version (in this case the 2, look in the middle of 0), and if it's required;
  • <uses-permission ...../>Those strings are simples, and are similar to permission in the use; they indicate which permission this app is authorized to use;
  •  <meta-data           
    android:name="com.google.android.maps.v2.API_KEY"
                android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />      
  • Here you must put your API KEY V2 instead of xxx...

- LET'S MODIFY OUR map.xml VIEW

adding a fragment that will contain our map. Google ha decided to use MapFragments instead of MapView, probably for increasing performances. However that is, so do like in the pic

1.4 Adapting you map view

Ok, we have updated the manifest, and added the fragment to the view. Now we have to

- IMPORT google-play-services_lib AS A PROJECT LIB

First of all we have to right click on the white space of our package explorer, then select import and choose "EXISTING ANDROID CODE INTO WORKSPACE"; 

BE CAREFUL: DON'T "EXISTING PROJECT INTO WORKSPACE"!!!


Then browse into you android-sdk directory, and go into

<your_android-sdk_DIRECTORY>\extras\google\google_play_services\libproject

 and click on finish.

1.5 How to import google-play-services_lib as project lib

Wow! You're great! That was the worst! Now let's see how 

- ADD THIS LIB INTO OUR PROJECT 

Yes, OUR, not YOUR, cause I've teached you how to make it, and your project is mine too!
So right click on OUR project, click on Properties, then Android tab. Go down after your list of Android devices, and finally you've reached the Library section.
Click on "Add" button, and select "google-play-services_lib", then OK.

1.6 Add google-play-services_lib into our project

WELL DONE, DELTA!
Now we must only

- LOAD OUR MAP FRAGMENT INTO OUR ACTIVITY

simply using this commenda, right after setContentView(R.layout.map);

map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_view)).getMap();

Let me say that the map is a private GoogleMap map; put outside the method onCreate(), into the Activity. Here is the code of map Activity