Code Bank
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingCode Bank

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 20th, 2005, 02:34 AM
ASP_man ASP_man is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 55 ASP_man User rank is Private First Class (20 - 50 Reputation Level)ASP_man User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 9 h 23 m 14 sec
Reputation Power: 0
Thumbs up Read an XML from an URL

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.
Comments on this post
Shadow Wizard agrees: thanks!
elijathegold agrees: Nice

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingCode Bank > Read an XML from an URL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT