External link problem get data from external XML file via classic ASP

82 Views Asked by At

I am using below code to get data from local file.

Source = "kur.xml"

Set kurlar = Server.CreateObject("msxml2.DOMDocument.6.0" )
kurlar.async = false
kurlar.resolveExternals = false
kurlar.setProperty "ServerHTTPRequest" ,true

kurlar.load(Source)

Set USD = kurlar.selectSingleNode("//Tarih_Date/Currency[@Kod = 'USD']")
USDS = USD.selectSingleNode("BanknoteSelling").text

Set EUR = kurlar.selectSingleNode("//Tarih_Date/Currency[@Kod = 'EUR']")
EURS = EUR.selectSingleNode("BanknoteSelling").text

But when I set xml source as external, I get "object required: 'USD'" error

Source = "https://www.tcmb.gov.tr/kurlar/today.xml"

By the way, both sources have exactly the same content.

Do I need to do something different when importing data from an external source?

Edit: This link doesn't work for me. My problem occurs when i use external source instead of local file. I solved my problem using ServerXMLHTTP with @John's suggestion.

1

There are 1 best solutions below

1
John On BEST ANSWER

I've tried your code and it works fine from where I am, but here's another approach

<% 
Source = "https://www.tcmb.gov.tr/kurlar/today.xml"
Set http = Server.CreateObject("msxml2.ServerXMLHTTP.6.0")
http.Open "GET", Source, False
http.Send

Response.codepage = 65001
Response.charset = "utf-8"

Set kurlar = Server.CreateObject("msxml2.DOMDocument.6.0" )
kurlar.loadXML http.responseText


Set USD = kurlar.selectSingleNode("//Tarih_Date/Currency[@Kod = 'USD']")
USDS = USD.selectSingleNode("BanknoteSelling").text

Set EUR = kurlar.selectSingleNode("//Tarih_Date/Currency[@Kod = 'EUR']")
EURS = EUR.selectSingleNode("BanknoteSelling").text

Response.write usds & ", " & eurs
%>