import {HttpClient } from '@angular/common/http';
constructor(
private http: HttpClient
) { }
leggiFileXML(): void {
const url = 'assets/dati.xml'; // Percorso del file XML (nella
cartella assets)
this.http.get(url, { responseType: 'text' }).subscribe({
next: (data) => {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(data, 'application/xml');
//Legg un nodo specifico
const elementi = xmlDoc.getElementsByTagName('nodo');
for (let i = 0; i < elementi.length; i++) {
console.log(elementi[i].textContent);
}
},
error: (error) => {
console.error('Si รจ verificato un errore:', error);
}
});
}
Di seguito la chiamata alla funzione per la lettura del file XML.
ngOnInit(): void {
this.leggiFileXML();
}
Nessun commento:
Posta un commento