读取phonegap android应用程序中的本地文件

Read local file in phonegap android application

本文关键字:文件 phonegap android 应用程序 读取      更新时间:2023-09-26

在我的phonegap android应用程序中,我在assets/www/文件夹中有一个xml文件。如何用javascript读取此文件的内容?

尝试使用此库http://www.fyneworks.com/jquery/xml-to-json/它将xml数据转换为易于使用的json。

此函数将加载xml文件:

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);
        });
    }

完整来源-https://gist.github.com/3106218

使用Cordova 1.7和Android 2.2 进行了测试