Tarak
Tarak

Reputation: 1212

Read local file in phonegap android application

In my phonegap android application, i have an xml file in assets/www/ folder.How can i read the content of this file in javascript?

Upvotes: 1

Views: 2440

Answers (1)

dhaval
dhaval

Reputation: 7659

Try using this library http://www.fyneworks.com/jquery/xml-to-json/ which converts the xml data into json which can be easily used.

This function will load the xml file:

function readXml(){
        $.get('data.xml', function(xml){

            // converts received XML document to string
            var xmlText = new XMLSerializer().serializeToString(xml);
            console.log(xmlText);

            var employees = $.xml2json(xml);
            console.log(employees)
            alert(employees.employee[0].name);
        });
    }

Full source - https://gist.github.com/3106218

Tested this with Cordova 1.7 and Android 2.2

Upvotes: 1

Related Questions