Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP code to read external XML document

Status
Not open for further replies.

intranetgeeky

Programmer
Jun 12, 2003
17
US
I've been all over the XML message boards and had no luck with this one. But I'm an ASP junkie and I know that you people can help.

I'm trying to get values from an external XML document using ASP. Does anyone know how to do this directly from my .asp page?

I've looked everywhere for an answer to this. And so far nothing has come even close.

Thanks,
~Brandon
 
Uh this seems too easy. The MSXML component can retrieve and parse XML documents.

Code:
var xmlSurvey   = Server.CreateObject("MSXML2.DOMDocument.4.0");


//When the basic document is missing the required element
//  it is necessary to turn off validation in order to extract data.
xmlSurvey.validateOnParse = false;


//The basic document may be stored on another computer.
xmlSurvey.async = false;
xmlSurvey.setProperty("ServerHTTPRequest",true);
var loadSuccess = xmlSurvey.load("[URL unfurl="true"]http://yourdomain/xml/surveyCA.xml");[/URL]



if(loadSuccess){

	//And so forth.
}

This component was free and could be downloaded from microsoft a couple of years ago. Now it is probably part of .NET and you probably need a new computer and an operating system upgrade to get it, I don't know.


 
Thank you for your response, but I'm confused by the code. I'm programming in ASP and you have semi-colons after each line.

This is the code that I have now. It can read from a copy of the external XML file that I have on my server. The problem is that I want it to read from the original that is located on a different server.

Code:
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load Server.MapPath("stockfeed.xml")

dim price
price = xml.getElementsByTagName("Symbol/@Last").item(0).text
response.Write(price)

Set xml = Nothing
%>

I tried doing xml.load " (with the location of the xml file) but it didn't recognize that. How do I load an external?

I tried xml.setProperty("ServerhttpRequest",true), but it gave me all kinds of errors. Any ideas?
 
If the remote file is located in a web directory on that server you could use XMLHTTP to retrieve the informationj and then use the LoadXML method of the XMLDOM object to load the response into your DOM object.

-Tarwn

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
minilogo.gif alt=tiernok.com
The never-completed website
 
Found the solution!

You have to use the XMLHTTP property to get the raw data from the XML file that is located on an external server. Then, the Call xmlhttp.send brings back the information that you can then parse and look for information. This example found an external XML file and printed one value from it.

Thanks for the lead Tarwn!

<%
Dim xmlhttp
'create object to retrieve XML via HTTP
Set xmlhttp = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)
xmlhttp.Open &quot;GET&quot;, &quot; false
Call xmlhttp.send

Dim xml

Set xml = Server.CreateObject(&quot;Microsoft.XMLDOM&quot;)

xml.loadxml(xmlhttp.responseText)


dim price
'find the node that we want and put it's value in a variable
price = xml.getElementsByTagName(&quot;Symbol/@Last&quot;).item(0).text
response.Write(&quot;Company's current price is: &quot; & price)

Set xmlhttp = Nothing
Set xml = Nothing
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top