如何阅读&在apache cordova中写外部xml文件?

时间:2016-07-06 12:05:31

标签: javascript jquery ajax cordova apache-cordova

我正在创建Android应用程序。我想使用xml文件只是为了在短时间内存储少量数据。 我能够使用ajax.get()方法文件读取xml但无法编写xml .. 请帮我这样做..

1 个答案:

答案 0 :(得分:1)

如果您想存储少量数据并且使用的是cordova,则可以使用get和set local storage:

localStorage.setItem("lastname", "Smith");

var agentSmith=localStorage.getItem("lastname");

正如w3school所说:

  

使用本地存储,Web应用程序可以在本地存储数据   用户的浏览器。

但是如果你想使用xml,你可以这样做:

var v = new  XMLWriter();
   v.writeStartDocument(true);
   v.writeElementString('test','Hello ');
   v.writeAttributeString('foo','bar');
   v.writeEndDocument();
   console.log( v.flush() );

并获得:

<?xml version="1.0" encoding="ISO-8859-1" standalone="true" ?>
<test foo="bar">Hello World</test>

喜欢这里create and modify xml file using javascript