Web Services extensible markup language - android

If i want connect extensible markup language web services with android application what can i do and what the difference if i use java-script object notation web services with android

IF you want to compare XML and JSON format ( what would be better with android). Please see some points here:
JSON is both more compact and (in my view) more readable - in transmission it can be "faster" simply because less data is transferred.
In parsing, it depends on your parser. A parser turning the code (be it JSON or XML) into a data structure (like a map) may benefit from the strict nature of XML (XML Schemas disambiguate the data structure nicely) - however in JSON the type of an item (String/Number/Nested JSON Object) can be inferred syntactically.
If you find performance to be an issue (I'm making this suggestion because these libs make you super productive), there are mechanisms in both to allow you finer grained control. I doubt you'll have problems with performance though.
I can think of to use XML over JSON is when your webservice responses are huge. JSON usually requires the entire response to arrive before you can start parsing.
You can reach more example about them on internet, and do some android test to see the performance as well.
Example of JSON parsing in Android you can find in this Restful_Webservice_Call_And_Get_And_Parse_JSON_Data-_Android.
Example of XML parsing in Android you can find in this XML_Parsing_Android.
Hopefully, it would be helpful for you!

Related

what is the purpose of using JSON in android?

I need to know the purpose of using JSON in android ?
Please anyone tell me in a simple way...
Thanks
The same reason you'd use it on any platform. JSON is a way of storing and expressing information. It uses attribute-value pairs in a hierarchical structure. In Android specifically, you may need to download some information from a database, which could be stored in JSON and then read by your app. Alternatively, you could store data locally in JSON but there are probably better and more efficient ways to do that if you're not sending data across a network.
https://en.wikipedia.org/wiki/JSON
JSON is very light weight, structured, easy to parse and much human readable. JSON is best alternative to XML when your android app needs to interchange data with your server
For example, you can get data Json if you work with database. Or if you work with some API's then you can get data in format Json.
For example an app could fetch data from a server. When using JSON to get the data, the traffic is quite small and the app can easily work with it.
For example you have a server with a database with recipes, and your app displays recipes, the app could ask the server for recipes, and it gets a JSON in return. for example:
{
name: 'Cookies'
ingredients: { 'Butter', 'Eggs', ... /* I don't know, I'm not a chef :D */
...
}
The app can then just read the properties and display them in a neat list ;)
JSON (JavaScript Object Notation) is a lightweight format that is used for data interchanging. It is also a subset of JavaScript's Object Notation (the way objects are built in JavaScript
Pls go through this link: http://www.copterlabs.com/blog/json-what-it-is-how-it-works-how-to-use-it/
JSON stands for JavaScript Object Notation
JSON is lightweight text-data interchange format
JSON is language independent *
JSON is "self-describing" and easy to understand
* JSON uses JavaScript syntax for describing data objects, but JSON is still language and platform independent. JSON parsers and JSON libraries exists for many different programming languages.
Using JSON in Android is not different than using it on any other platform. The main advantage of the format (in comparison to XML for example) is the small size of the data. This is very important for mobile devices due to the scarce resource those application use - i.e. your mobile app should be able to run with little memory usage, slow internet connection and so on.
Besides Android's framework has built-in tools for parsing / creating JSON objects. Thus it is both easy and efficient to use JSON rather than XML. If you have any project specific reason to prefer another data presentation format - don't worry. It is perfectly fine NOT to use JSON as long as some other format is more suitable for your project.
In short JSON is usually the right choice due to its small footprint and easy of use.

Do you advise clients to use JSON or XML? And Why?

Many times my client ask me whether they will deliver data via XML feed or JSON strings. I usually say:
XML if you already have a feed and do not have a web developer who will create script for generating JSON strings
JSON if you do not have any feed and need to create any from the scratch
What do you say? Do you think that delivering data via XML feeds is obsolete and that XML is over-complicated and too heavy?
Should I advise all clients (for the sake of the future) to move onto JSON way of delivering data?
EDIT
From another discussion https://stackoverflow.com/questions/2636245/choosing-between-json-and-xml I can see that JSON is advised for web services, which is the most used case scenario in my clients. It seems that I was advising them properly.
What is they want to pass news articles onto a mobile device - shall I advise XML of JSON?
What about post&get cases when I need to post some data and the to get the response which will be displayed on user's mobile device - XML or JSON?
If the consumers are browsers or mobile devices, I would recommend JSON.
Faster
Lighter
Native parsing support
If the consumers are other programs, I would recommend XML
Can be validated easily
Code generators available to make programming easy and is less error-prone
JSON - if you have a choice :) Google GSON is a serious help there.
We Use JSON: If we want to serialize a data structure that’s not too text-heavy and all you want is for the receiver to get the same data structure with minimal effort
We use XML:If we want to provide general-purpose data that the receiver might want to do unforeseen weird and crazy things with, or if you want to be really paranoid and picky about i18n, or if what you’re sending is more like a document than a struct, or if the order of the data matters, or if the data is potentially long-lived.
This discussed topic might help you .
I agree with all the other recommendations for JSON, but for me the main reason for going with JSON is it's far easier to process on the server especially if you are using a language that supports the JSON structure natively (e.g NodeJS or Python).
I would not say XML is obsolete though. The one obvious case where XML wins is readability. As a programmer I would say JSON is just as readable but I've worked with a lot of people (mainly web designer types) who prefer the look and feel of XML, probably because they are already intimately familiar with HTML.
I agree with your assessment really. Json is easier (for a human) to read, more intuitive and lightweight. XML is better if you have lots of existing XML solutions/interfaces that you're plugging in to. I see XML as the established, mature heavyweight of structured documents, but you don't always need an established, mature heavyweight. It all depends on the use case.

Which is the best way to fetch/retrieve data from server in android? Is it Xml or Json

I am trying to upload & retrieve data with the server.
Which is the best way to retrieve data using xml or json ?
Thank you
As i have used both XML and JSON, and also used all parser including SAX, DOM, Pull Parser. I have also developed web-service for JSON and XML both.
So I suggest you to go with JSON. why?
Because webservice for JSON response seems to develop easily, we don't need to do anything for creating JSON response, we just have to do json_encode() in PHP.
And while in Android, we can parse the JSON string easily by writing less code.
since it supports both.It depends on your feasibility.better go with json as it is easy to implement
I've just done an app that exchanges data over the wire with an API using Google's protocol buffers. There's a neat Java library available from Google for generating the java objects based on your proto files and other libraries to use for parsing an input stream into objects.
Really fast, very low bandwidth, though a bit of an overhead to setup and there's no readable data that you can drop into Notepad to view if you're having trouble.
IMHO the point of choosing one of them goes mainly down to the data size that needs to be transferred to the client. Obviously that should be as small as possible and so the preferred choice is usually
JSON
Google Protocol Buffers
..because they are much more concise than XML.
For data-oriented applications, I prefer JSON to XML due to its simplicity and ease of processing on the client side. XML may be great on the server side, but JSON is definitely easier to deal with on the client side.
have a look on the following url
http://www.subbu.org/blog/2006/08/json-vs-xml
Simplicity
XML is simpler than SGML, but JSON is much simpler than XML. JSON has a much smaller grammar and maps more directly onto the data structures used in modern programming languages.
Extensibility
JSON is not extensible because it does not need to be. JSON is not a document markup language, so it is not necessary to define new tags or attributes to represent data in it.
Interoperability
JSON has the same interoperability potential as XML.
Openness
JSON is at least as open as XML, perhaps more so because it is not in the center of corporate/political standardization struggles.
XML is human readable
JSON is much easier for human to read than XML. It is easier to write, too. It is also easier for machines to read and write.
XML vs JSON
JSON is better then XML that's it.

Is there an easy to use XML parser for remote database connection?

I am making an Android app, and I need to connect to a remote database with a webservice.
I will receive an XML file from the webservice with the results of my SELECT query (various rows in some cases).
I don't know much about XML or web services, I only know that I will receive an XML file and that I have to parse it to obtain the data.
Is there an XML parser for this purpose that is easy to add to my app and configure?
I would suggest not using XML and instead use JSON. JSON is much cleaner and much less in kilobytes. Then I would use Jackson to deserialize the JSON string to an object. You really don't need to do any work. Just point to the URL and you get an object back. You just have to make sure on the webservice you also generate correct JSON, which you can also use Jackson.
Here is how easy it is:
ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
User user = mapper.readValue(new File("user.json"), User.class); // can use File, URL, String!
Designing XML parsers are not very difficult. You can probably google for xml parsers and then change them to look for the tags you need or values.
Google is your friend.
You don't need an in depth knowledge about XML but you should know a bit about it. A recommended read would be this article. You should also at least know how the server is handling the communication. Is it a unidirectional communication (your application only fetching data) or is it a bidirectional communication (you are sending requests to the server). If the later how is the server handling them and so on. A bit of background knowledge is required.
I always recommend using the SAX parser as it seems so be the most efficient one due to its concept (being event based). A good read about dealing with XML files on Android can be found here. And also don't forget to search for similar questions here on StackOverflow as it is quite a popular question with some quality answers.

How to parse responses from a Django server in android?

In the Android application I am building, I want to be able to communicate with a local server developed in Django. (Basically a login page and a home page populated with posts and images from users) So do I need to use XML Parsers for the parsing the response from a Django server or is it possible for the server to respond with strings which can be directly used? Also what about images?
Is the JSON or XML Parser easier and robust to use in Android? The responses would be basically like tweets with a username, image and message. I was thinking of using the SAXParser. Any better alternatives?
Regards,
Primal
Android has built in libraries for parsing both JSON and XML.
In my opinion, the easier (and better) one would probably JSON if you're just looking to output the serialized version of your models.
Some relevant links:
JSON:
https://developer.android.com/reference/org/json/JSONObject.html
XML:
https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
https://developer.android.com/reference/javax/xml/parsers/package-summary.html
Edit: In response to the last part of your question, yes, you can just output strings. Depending on the complexity of your data, you'll end up making things harder for yourself. Parsing JSON on Android is super easy. Just do it.
SAXParser is very easy to use, it just calls a method when it enters a node with the name of the node and its arguments.
So yes, using SAX is a good idea.

Categories

Resources