Commit 1d8fbc65 authored by Administrator's avatar Administrator
Browse files

list dataset description in search page

parent 2972aa33
...@@ -7,11 +7,12 @@ ...@@ -7,11 +7,12 @@
<div *ngIf="!isXmlItemsEmpty()" class="w3-container"> <div *ngIf="!isXmlItemsEmpty()" class="w3-container">
<table class="w3-table-all w3-card-4"> <table class="w3-table-all w3-card-4">
<thead> <thead>
<tr style="text-align: center;">Uri dataset</tr> <tr style="text-align: center;">Dataset description</tr>
</thead> </thead>
<tbody> <tbody>
<tr *ngFor="let item of xmlItems"> <tr *ngFor="let item of xmlItems">
<td>{{item}}</td> <td>{{item.title.value}}</td>
<td>{{item.description.value}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
......
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import xml2js from 'xml2js';
import { ParseXmlService } from '../services/parse-xml.service'; import { ParseXmlService } from '../services/parse-xml.service';
...@@ -15,7 +14,7 @@ import { ParseXmlService } from '../services/parse-xml.service'; ...@@ -15,7 +14,7 @@ import { ParseXmlService } from '../services/parse-xml.service';
export class SearchComponent implements OnInit { export class SearchComponent implements OnInit {
public xmlItems: string[] = []; public xmlItems: string[][] = [];
constructor( constructor(
private http: HttpClient, private http: HttpClient,
...@@ -30,68 +29,33 @@ export class SearchComponent implements OnInit { ...@@ -30,68 +29,33 @@ export class SearchComponent implements OnInit {
//curl -X POST -H 'Accept: application/rdf+xml' -i 'http://10.6.10.9:8888/blazegraph/sparql' --data 'query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }' //curl -X POST -H 'Accept: application/rdf+xml' -i 'http://10.6.10.9:8888/blazegraph/sparql' --data 'query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'
let query: string; let query: string;
let parser = new xml2js.Parser(); // query ='query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'
query ='query=SELECT * where {?s a <http://www.w3.org/ns/dcat#Dataset> }'
const httpOptions = {
headers: new HttpHeaders({ query=
'Accept': 'application/rdf+xml', 'query=PREFIX dcat: <http://www.w3.org/ns/dcat#>\n\
'Content-Type': 'application/x-www-form-urlencoded', PREFIX dcterms: <http://purl.org/dc/terms/>\n\
'responseType': 'text' SELECT ?title ?description\n\
}) where {\n\
}; ?dataset a dcat:Dataset ;\n\
/* dcterms:title ?title ;\n\
this.http.post("http://10.6.10.9:8888/blazegraph/sparql", dcterms:description ?description.\n\
query, }'
{headers: new HttpHeaders()
.set('Content-Type', 'aapplication/rdf+xml')
.set('Content-Type', 'application/x-www-form-urlencoded')
.append('Access-Control-Allow-Methods', 'POST')
.append('Access-Control-Allow-Origin', 'http://localhost:4200')
.append('Access-Control-Allow-Headers', "Access-Control-Allow-Headers, Access-Control-Allow-Origin, Access-Control-Request-Method")
})
.subscribe((data) => {
this.parseXML(data)
.then((data) => {
this.xmlItems = data;
});
}); */
this.parserService.getXmlResult("http://10.6.10.9:8888/blazegraph/sparql",query).subscribe( this.parserService.getXmlResult("http://10.6.10.9:8888/blazegraph/sparql",query).subscribe(
data=>{ data=>{
if (data){ if (data){
console.log("Data : ", data.results.bindings[0].s.value);
data.results.bindings.forEach(element => { data.results.bindings.forEach(element => {
console.log("element : ", element.s.value) this.xmlItems.push(element);
this.xmlItems.push(element.s.value);
}); });
} }
}) })
return null; return null;
} }
parseXML(data) {
return new Promise(resolve => {
let k: string | number,
arr = [],
parser = new xml2js.Parser(
{
trim: true,
explicitArray: true
});
parser.parseString(data, (err, result) => {
console.error("Object found : ", result);
var obj = result.results;
for (k in obj.result.bindings.s) {
var item = obj.result.bindings.s[k];
arr.push({
uri: item.uri[0]
});
}
resolve(arr);
});
});
}
isXmlItemsEmpty(){ isXmlItemsEmpty(){
return this.xmlItems.length === 0; return this.xmlItems.length === 0;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment