If you need to obtain an XML DOM document from an URL, here's how -
Code:
Dim URL, count, objXML, i, counter
URL = "http://www.mysite.com/Broker.xml"
Set objXML = Server.CreateObject("MSXML2.DOMDOCUMENT.4.0")
'Using the "server-safe" ServerXMLHTTP component to load the document to the server.
'ServerXMLHTTP only supports synchronous loading;
objXML.setProperty "ServerHTTPRequest", True
objXML.async = False
objXML.Load(URL)
If objXML.parseError.errorCode <> 0 Then
Response.Write(objXML.parseError.reason)
Response.Write(objXML.parseError.errorCode)
End If
objXML is your DOM object. You can access any of the XML elements as defined in the standard DOM methods like so -
Code:
Response.Write objXML.getElementsByTagName("product").getElementsByTagName("lang").item(0).Text
However, if the server that dishes out this page is not the same as the URL mentioned in the 'URL' variable (www.mysite.com), the client browser will not allow this request. This is a security feature built into all browsers. Hence this piece of code need be done as a server side script.
To do this in Javascript (again note that the URL accessed by the XMLHttpRequest object should be in the same domain as the domain serving the page) -
Code:
function loadXMLDoc()
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
URL = "http://www.mysite.com/Broker.xml"
xmlDoc.async="false";
xmlDoc.onreadystatechange=processReqChange;
xmlDoc.load(url);
}
function processReqChange()
{
xmlObj=xmlDoc.documentElement;
if (xmlDoc.readyState == 4)
{
productname = xmlObj.getElementsByTagName("product").item(i).getElementsByTagName("lang").item(0).text;
}
}
If you do need to do a cross domain request, the end users browser must have the site that serves this page in it's list of 'Trusted Sites' (which you obviously can't ask every user to do). So the best solution would be to submit the form and call the scripts at the server.
This bottom line is you aren't
allowed to make XMLHttpRequests to any server except the server where your web page came from.