Reading from an xml file

Hi I’m trying to import an xml file into my app from a directory within my application code, to use as reference data, is there a ‘best practice’ way of doing this? My end goal is to pre populate a application specific database with the xml data.

Thanks in advance


Use $http$http

I dont think that you can read a file using the $http service, please correct me if I am wrong but I’m sure it’s only for consuming web end points?

I may have found the solution:

I’ll post back here when I have given it a shot.

  1. i think you can request all files of type ‘xml, json, script, or html’ via $http with a GET-Request and it will return the file-content
  2. you can load a file from your phone over the file-plugin FileReader… and so on.

Greetz, bengtler

I searching for the same answer, i receive xml from a webservice and need to converto to JSON, can cordova file do this task ? or what is the best way ?

There are some native javascript parsers.

and there is also an own jquery-plugin.

But keep in mind xml code can contain characters or structurs which would be invalid in json so the converting can fail!
So the best solution is to extend the API to return also JSON-Data if you want.

Nowadays nobody would build a xml-API for Web-/ Mobile-Apps.

I found this class, try and it works: so i will consume the xml webservice, generate the json output webservice.

Yep simpleXML for php is a good choice.

which is the best way to read data from app loicaly waiting for your reply

two ways:

  1. The file is stored in your application folder --> you can simply make a get request
  2. The file is stored somewhere else accessible in your app --> use cordova file to mount the correct file system and access the file

But your question has nothing to do with the original topic right? :wink:

Thanks for your reply,
Yes :grin: