2009-08-16 4 views
1

이것이 가능한지 확실하지 않은데, 모든 종류의 MYSQL 또는 데이터베이스에 대한 액세스 권한이없는 웹 사이트에서 작업하고 있습니다. PHP도 마찬가지입니다. 저렴한 고객데이터가 연결된 여러 XML이 있습니까?

데이터의 다른 부분이있는 3 개의 XML 파일이 있더라도 관계없이 "키"를 배치했습니다. 나는 간단한 IF 문이 일치를 할 것이라고 믿는다.

그러나 3 개의 XML 파일을 호출하고 모든 XML 파일에서 데이터를 가져 와서 루프로 결합하는 가장 좋은 방법은 무엇입니까?

가 내가 변수를 만들고 싶습니다

는 "monHTML"나는 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)); 
     }); 
     } 
    }); 
모든 합병 : 여기

그들 중 하나를 끌어 작동 코드 "monHTML"var에 입력하십시오. 서버에있는 파일을 병합 할 수 없기 때문에

어떤 아이디어? "

답변

1

당신은 3 개 독립적 인 아약스 요청을 수행해야합니다. 어려움은 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에서 다른 데이터로 연결하는 방법입니다. 비교할 항목을 선택하여 연결할 수 있습니까? – matthewb

0

당신의 클라이언트가 네이티브 XML 데이터베이스를 감당할 수있을 것 몇 가지를 eXist-org가 시작하는 곳입니다. 그런 다음 XQuery를 사용하여 문제를 해결할 수 있습니다. 이 문제는 더 쉽게.

관련 문제