Is there any way to fetch data in XML file? I want to create an App that shows feed lists, like in facebook and I will get the data in XML.
I am new in developing an Android App.
Thank you!
Is there any way to fetch data in XML file? I want to create an App that shows feed lists, like in facebook and I will get the data in XML.
I am new in developing an Android App.
Thank you!
I just did this myself actually. Make sure your have the $http dependency. Download the X2JS library. Then it’s as simple as:
$http.get("/data/appdata.xml").success(function (data) {
var x2js = new X2JS();
var jsonData = x2js.xml_str2json(data);
});
can you please give me some sample app that fetch data from XML? Thanks!
Like Emir wrote, to fetch data from a xml file you can send an ordinary GET-Request to its destination.
AngularJS provides therefore the $http service.
With $http.get(URL) you make a get request to this url/path.
if your request was successfully finished ->
$http(URL).success(function (data) {
// success case
});
is called.
On “data” you will found your xml content of the file.
To work with xml data you need to convert the xml-structur (string) to an object.
That is why Emir referenced the X2JS module.
with
var x2js = new X2JS();
var jsonData = x2js.xml_str2json(data);
you will create a new X2JS intance, which has a method xml_str2json. This function accepts one parameter (the xml-data-string) and converts this to an object.
This is a real full example for your purpose.
If you do not know how to include external javascript libs or sending requests… you have to read some tutorials about.
Thank You very much. I have not asked you directly anything. But This answer has helped me a lot