gpt4 book ai didi

xml - 是否有一个 cordova 插件可以从 config.xml 中读取值?

转载 作者:数据小太阳 更新时间:2023-10-29 01:41:44 25 4
gpt4 key购买 nike

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

  • 姓名
  • 版权
  • 描述

然而,惊讶地发现 API 引用指南中没有“Config”功能: http://cordova.apache.org/docs/en/3.4.0/index.html

我已经求助于编写自己的函数来手动读取和解析该文件,但是我觉得必须有一种(现有的)更好的方法。

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

最佳答案

您可以在 iOS、WP7、WP8、Windows8 和可能的 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();
}

对于 Android,您必须将文件路径从 "../config.xml" 更改为 "../../android_res/xml/config.xml"

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

还有非官方的读取配置的插件: https://github.com/apache/cordova-labs/tree/cdvtest/cordova-plugin-appsettings

关于xml - 是否有一个 cordova 插件可以从 config.xml 中读取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22744269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com