是否有cordova插件从config.xml中读取值? [英] Is there a cordova plugin to read values from config.xml?

查看:764
本文介绍了是否有cordova插件从config.xml中读取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时从我的Cordova / PhoneGap应用程序的 config.xml 中读取这些值:

I wish to read these values from my Cordova/PhoneGap application's config.xml at runtime:


  • 姓名

  • 版权

  • 描述

但是,很惊讶,API参考指南中没有 Config 功能:
http://cordova.apache.org/docs/en/3.4.0/index.html

However, was surprised to see there is no 'Config' feature in the API reference guide: http://cordova.apache.org/docs/en/3.4.0/index.html

我诉诸于编写我自己的函数,手动读取和解析这个文件,但我觉得必须有一个(现有的)更好的方法。

I've resorted to writing my own function that reads and parses this file manually, however I feel like there must be an (existing) better way.

如果开发人员手动解析config.xml以提取必要的信息,或者是否有可用于执行此操作的现有插件? / p>

Should developers be parsing config.xml manually to extract necessary info, or is there an existing plugin that can be used to do this?

推荐答案

您可以在iOS,WP7,WP8,Windows8以及Ubuntu上使用以下代码

You could use following code on iOS, WP7, WP8, Windows8, and probably Ubuntu

function readConfig() {
    var xhr = new XMLHttpRequest();
    xhr.addEventListener("load", function () {
        var parser = new DOMParser();
        var doc = parser.parseFromString(xhr.responseText, "application/xml");
        alert("Description : " + 
              doc.getElementsByTagName("description").item(0).textContent);
    });
    xhr.open("get", "../config.xml", true);
    xhr.send();
}

您必须从../ config.xml../../ android_res / xml / config.xml

取自Cordova邮寄,其中讨论了答案:
https://www.mail-archive.com/dev@cordova.apache.org/msg14313.html

Taken from Cordova mailing where discussed answer: https://www.mail-archive.com/dev@cordova.apache.org/msg14313.html

此外有非官方插件用于deisred功能:

Also there non-official plugin for deisred functionality:

还有没有官方插件阅读配置:
https://github.com/apache/cordova-labs/tree/cdvtes​​t/cordova-plugin-appsettings

Also there not-official plugin for reading configuration: https://github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings

这篇关于是否有cordova插件从config.xml中读取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆