jQuery的:合并XML文档 [英] jquery: merge XML documents

查看:71
本文介绍了jQuery的:合并XML文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是有可能的合并多个xmlDocuments成一个单一的文件(VAR newResult)通过使用jQuery(或纯JavaScript)?

is it possible to merge multiple xmlDocuments into one single file (var newResult) by using jquery (or pure javascript) ?

不幸的是,我到不同的托管XML的文档合并到一个单一的文件(不要问我为什么...)。我打得周围不同的技术,但我不能找到一个解决方案(也许jQuery是没有准备好XML处理?)。谢谢:)

unfortunately i've to combine different hosted xml-documents into one single file (don't ask me why...). i've played around with different techniques, but i can't find a solution for this (maybe jquery isn't ready for xml-handling??). thank you :)

看我的一片code:

var files = ['john.xml','doe.xml']
var newResult, temp;

function loadMyXMLFiles(){

    // > let's load file by file using jquery's ajax-call:

    $.each(files, function(index,value) { 

      $.ajax({

          url: value,
          cache: true,
          success: function(data){

            // > check if temp is empty, append or fill

            (temp) ? temp += (data) : temp = data;


            // > on complete:

            if (index == files.length-1) {

                xmlResult = temp; temp = null;
            }
          }

      });
  });
}

loadMyXMLFiles()

推荐答案

正如我所看到的,你想将它们连接起来。如果这是你需要什么,你的code还不错,

As I can see, you are trying to concatenate them. If this is what you need, your code wasn't that bad,

var files = ['john.xml','doe.xml']
var xmlResult, temp = ""; //Make temp an empty string

loadMyXMLFiles(){
    $.each(files, function(index,value) { 
      $.ajax({
          url: value,
          cache: true,
          async: false, //This is crucial!
          success: function(data){
            temp += data;
            if (index == files.length-1) {
                xmlResult = temp; temp = null;
            }
          }
      });
  });
}

您必须使用异步:假让你的文件按顺序到达。但谨慎,直到处理完成,这将挂起浏览器。如果它是至关重要的是不要发生,只是告诉我。

You have to use async: false so your files arrive in order. But caution, this will hang the browser until the processing is finished. If it's vital for it not to happen, just tell me.

希望这有助于。干杯

这篇关于jQuery的:合并XML文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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