简体   繁体   中英

How to import data from a xml link to a HTML website

I'm setting up a new website with all the live currency from a bank. The bank provides us with a link for the xml file.

https://www.bnr.ro/nbrfxrates.xml

My question is how can I import the data from the provided link and make a table on my HTML website?

You can do it with Javascript. So first you can get all the data from the XML in an Array like this

var request = new XMLHttpRequest();
request.open("GET", "https://www.bnr.ro/nbrfxrates.xml", false);
request.send();
var xml = request.responseXML;
var currencies = xml.getElementsByTagName("Rate");
for(var i = 0; i < currencies.length; i++) {
    $currency = currencies.attributes["currency"];
    $value = currencies.nodeValue;
}

This is how you get the data from the XML.

Here is a good explanation how you dynamically create an html table. Dynamically creating an html table with Javascript
I hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM