html로 sparql 쿼리를 만들려고합니다. 이 코드가 있습니다.
<script type="text/javascript">
document.write("<strong>Hola!</strong>");
var SPARQL_ENDPOINT = 'http://datos.zaragoza.es/sparql';
var query = 'PREFIX pproc: <http://contsem.unizar.es/def/sector-publico/pproc#>\
PREFIX dcterms: <http://purl.org/dc/terms/>\
SELECT DISTINCT ?uri ?titulo ?servicioGestor WHERE {\
?uri a <http://contsem.unizar.es/def/sector-publico/pproc#Contract>;\
dcterms:title ?titulo;\
pproc:managingDepartment ?managingDepartment.\
?managingDepartment dcterms:title ?servicioGestor} ORDER BY ?titulo';
이제 브라우저에서 파일을 열 때 쿼리 결과를 볼 수 있도록 완료해야합니다.
다음을 수행해야합니다.
해당 엔드 포인트와 쿼리를 사용하여 쿼리에 대한 전체 URL을 작성합니다. 결과를보다 쉽게 처리 할 수 있도록 JSON 형식으로 결과를 요청할 수 있습니다. 쿼리와 형식은 URL로 인코딩되어야합니다. 예 :
var url = SPARQL_ENDPOINT
+ '?query=' + encodeURIComponent(query)
+ '&format=' + encodeURIComponent('application/sparql-results+json');
해당 URL에 대한 GET 요청을 작성하십시오. 이에 대한 많은 코드가 온라인에서 제공됩니다.
그런 다음 반환 된 JSON 결과를 구문 분석하고 표로 표시 할 수 있습니다.
function printTable(response){
var results = JSON.parse(response);
var table = '<table>';
results.results.bindings.forEach(function (result){
table += '<tr><td>' + result.uri.value + '</td><td>' + result.titulo.value
+ '</td><td>' + result.servicioGestor.value + '</td></tr>';
})
table += '</table>';
document.write(table);
}
를 추가 console.log(results);
하여 브라우저 Javascript 콘솔 창에서 전체 결과를보고 정확히 표시 할 내용을 파악하십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다