用于解析xml文档的Javascript代码

用于解析xml文档的Javascript代码,javascript,android,cordova,restful-authentication,alfresco,Javascript,Android,Cordova,Restful Authentication,Alfresco,我想要一个调用web脚本的javascript代码(http://10.0.2.2:8080/alfresco/service/api/login?u=admin&pw=admin)使用Phonegap在android应用程序中远程调用alfresco,并使用返回结果,将此返回结果附加到alfresco的webscript的其他调用中(http://localhost:8080/alfresco/service/sample/folder/Company%20Home?format=atom).

我想要一个调用web脚本的javascript代码(http://10.0.2.2:8080/alfresco/service/api/login?u=admin&pw=admin)使用Phonegap在android应用程序中远程调用alfresco,并使用返回结果,将此返回结果附加到alfresco的webscript的其他调用中(http://localhost:8080/alfresco/service/sample/folder/Company%20Home?format=atom).. 请帮我做这个

我有这个示例代码,如何根据需要更改它…我想调用解析返回值并将其附加到webscript的另一个调用中


功能负重(){
警报(“我们正在调用jquery的ajax函数,成功后回调xml解析完成”);
$.ajax({url:'http://www.edumobile.org/blog/uploads/XML-parsing-data/Data.xml',
网址:'
数据类型:'application/xml',
超时:10000,
类型:'POST',
成功:功能(数据){
console.log(“客户选项卡”,数据);
$(“#bookInFo”).html(“”);
$(“#bookInFo”)。追加(“
”); $(数据)。查找(“书籍”)。每个(函数(){ $(“#bookInFo”).append(“
名称:”+$(this.find(“Name”).text()); $(“#bookInFo”).append(“
地址:”+$(this.find(“地址”).text()); $(“#bookInFo”).append(“
国家:”+$(this.find(“国家”).text()); $(“#bookInFo”)。追加(“

”); }); }, 错误:函数(XMLHttpRequest、textStatus、ErrorSprown){ 警报(“错误状态:+textStatus”); 警报(“错误类型:“+ErrorSprown”); 警报(“错误消息:+XMLHttpRequest.responseXML”); $(“#bookInFo”).append(XMLHttpRequest.responseXML); } }); } 买票

对于类似xml的

<test>
  <something>
      <data>Data1</data>
      <other>Other1</usage>
  </something>
  <something>
      <data>Data1</data>
      <other>Other1</usage>
  </something>
</test>

让我知道它是否对您有帮助。

我对Javascript不太清楚,因为我在android中探索了使用phonegap解析xml是通过调用Ajax调用和jquery完成的(我无法将其与我的需要联系起来……我已经厌倦了看上面的示例……您可以使用E4x在javascript中进行xml解析:@MatjazMuhic在使用Phonegap的android应用程序中是否支持此功能?我不确定。但我认为android和Phonegap与javascript本身无关。我认为它包含在javascript中。
<test>
  <something>
      <data>Data1</data>
      <other>Other1</usage>
  </something>
  <something>
      <data>Data1</data>
      <other>Other1</usage>
  </something>
</test>
$.ajax({
    type : 'GET',
    url : "http://some-url:8080/test.xml",
    data : {
        key : "value"
    },
    dataType : "xml",
    success : function(xml) {

        data1 = $(xml).find('data').eq(0).text();
        data2 = $(xml).find('data').eq(1).text();

        other1 = $(xml).find('other').eq(0).text();
        other2 = $(xml).find('other').eq(1).text();

    },

    error : function(xhr) {
        alert("Error while loading!!!");
    }
});