2009-08-16 10 views
1

これが可能かどうかはわかりませんが、私はどのような種類のMYSQLやデータベースにもアクセスできないWebサイトで作業しています。 PHPもありません。安いクライアントデータがリンクされた複数のXML?

私は3つの異なるXMLファイルを持っていますが、お互いに一致する "キー"を配置しています。私は単純なIF文がマッチングを行うと信じています。

しかし、3つのXMLファイルを呼び出してそれらのすべてからデータを取り出して、ループにまとめる最良の方法は何ですか。ここで

は、そのうちの一つを引っ張って動作するコードは次のとおりです。

$.ajax({ 
    type: "GET", 
    url: "xml/classes.xml", 
    dataType: "XML", 
    beforeSend: function(){ 
    $('#classContainer').append("<p>Loading</p>");}, 
    success: function(xml) { 
    $(xml).find('monday').each(function(){ 

      var $classdate = $(this); 
      var title = $classdate.find("class").attr('title'); 

      var level = $classdate.find("class").attr('classLevel'); 
       var time = $classdate.find("time").text(); 
       var duration = $classdate.find("time").attr("duration"); 
       var hourofday = $classdate.find("time").attr("hourofday"); 
       var location = $classdate.find("location").text(); 



      var Monhtml = '<div class="classBlock">'; 

      Monhtml += '<p class="title">' + title + '<span class="loadingPic" alt="Loading" /> ' + ' </p>'; 
       Monhtml += '<p class="infoBar"> <strong>Time:</strong>' + time + '<span class="hour">'+ hourofday +'</span><br>'+'<strong>Duration:</strong>' + duration +' Minutes <br>' + '<strong>Location:</strong>' + location + '<br><strong>Instructor:</strong> </p>'; 
       Monhtml += '<p class="description"> <span class="level">' + level + '</span></p>' ; 

      Monhtml += '</div>'; 


      $('#classContainer').append($(Monhtml)); 
     }); 
     } 
    }); 

私はすべてのマージされた3つのXML文書から変数のセットを持っているでしょう「monHTML」に配置する変数を作成したいです"monHTML" varにコピーします。あなたは、サーバー上のファイルをマージすることはできませんので

任意のアイデア」?

答えて

1

あなたは、3つの独立したAJAXリクエストを実行する必要があります。難易度は3つのリクエストを同期に構成されています。彼らは、同期的に実行することができますが、これは意志間違いなくパフォーマンスを傷つけると、タイムアウトが発生する可能性がより良い方法は、非同期的に3つのリクエストを送信し、3件のリクエストが完了したら、コールバックを呼び出すためにあることである:。。

var addreses = ['xml/file1.xml', 'xml/file2.xml', 'xml/file3.xml']; 

var ajaxQueue = { 
    files   : [], 
    checkFinished : function() { 
     if (this.files.length == addresses.length) { 
      // You can work with the 3 xml files here... 
      // this.files will be an array of elements that contain 
      // url and xml parameters. Check the url parameter to identify the 
      // corresponding xml. 
      // Remark: as the order in which the requests finish can vary, the array 
      // will not be sorted. 
     } 
    }; 
}; 

$(addreses).each(function(index, address) { 
    $.ajax({ 
     url  : address, 
     dataType : 'xml', 
     success : function(data) { 
      ajaxQueue.files.push({ url: address, xml: data }); 
      ajaxQueue.checkFinished(); 
     } 
    }); 
}); 
+0

これは今のところ最良の選択肢のようですが、もう1つの問題は特定のデータを1から別のものに接続する方法です。 あなたはそれを比較するものを選択して接続できますか? – matthewb

0

あなたのクライアントは、ネイティブXMLデータベースを買う余裕することができるかもしれないいくつかの自由で良い - eXist-org。は始める場所です.XQueryを使って解くことができますこの問題はより簡単に起こります。

関連する問題