vcgDevelopers
asked on
Parsing XML response with ASP
I am developing a website where I need to parse an XML response form a remote database. I can parse an XML file that is local to my computer but have problems grabbing the XML as an HTTP request.
Any help would be greatly appreciated!
Eleon
Any help would be greatly appreciated!
Eleon
ASKER
I tried using the function and hard coding the url but can not open the XML response. Is there a chance the MSXML library is not visible?
Eleon
Eleon
I am not sure. If you would like to try this with my site to see, use http://www.FaifieldConsulting.com a shot.
FtB
FtB
ASKER
Thanks for you help. I've been a C programmer and was thrown into the HTML/XML/ASP deep end since no one else in my company wanted to do the job... Well, I was able to grab the XML response, it turned out to be a password error. The result comes back as a string and is difficult to parse since blanks occur not only between tag values. Is there a way to get the tag names with the text?
Eleon
Eleon
I thought that did return tag names. Hang on a few minutes...
FtB
FtB
I guess that this just renders the page...
<%
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
Function GetHTML(strURL)
Dim objXMLHTTP, strReturn
Set objXMLHTTP = Server.CreateObject("MSXML 2.ServerXM LHTTP")
objXMLHTTP.Open "GET", strURL, False
objXMLHTTP.Send
strReturn = objXMLHTTP.responseText
Set objXMLHTTP = Nothing
GetHTML = strReturn
End Function
response.write(GetHtml("http://www.FairfieldConsulting.com/datacontent.xml") )
%>
<%
Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"
Function GetHTML(strURL)
Dim objXMLHTTP, strReturn
Set objXMLHTTP = Server.CreateObject("MSXML
objXMLHTTP.Open "GET", strURL, False
objXMLHTTP.Send
strReturn = objXMLHTTP.responseText
Set objXMLHTTP = Nothing
GetHTML = strReturn
End Function
response.write(GetHtml("http://www.FairfieldConsulting.com/datacontent.xml")
%>
ASKER
What is the best way to grab the return, xsl stylesheets? I may have to run out and buy another book..
Eleon
Eleon
vcg, you may want to try this for grabing return from a url, if you have trouble with MSXML
<%
Dim URL
URL = "http://google.com"
HtmlDump = HttpRequest(URL)
if IsNull(HtmlDump) then
response.write "problem with URL - " & URL
else
response.write "html dump from URL - " & URL
response.write "<form><textarea cols='80' rows='20'>"
response.write HtmlDump
response.write "</textarea></form>"
end If
response.end
Function HttpRequest(ByVal URL)
Set WinHttpReq = CreateObject("WinHttp.WinH ttpRequest .5.1")
WinHttpReq.Open "GET", URL, False
WinHttpReq.Send
If WinHttpReq.status = 200 Then
HttpRequest = WinHttpReq.ResponseText
Else
HttpRequest = Null
End If
Set WinHttpReq = Nothing
End Function
%>
Let me know if this works for you.
<%
Dim URL
URL = "http://google.com"
HtmlDump = HttpRequest(URL)
if IsNull(HtmlDump) then
response.write "problem with URL - " & URL
else
response.write "html dump from URL - " & URL
response.write "<form><textarea cols='80' rows='20'>"
response.write HtmlDump
response.write "</textarea></form>"
end If
response.end
Function HttpRequest(ByVal URL)
Set WinHttpReq = CreateObject("WinHttp.WinH
WinHttpReq.Open "GET", URL, False
WinHttpReq.Send
If WinHttpReq.status = 200 Then
HttpRequest = WinHttpReq.ResponseText
Else
HttpRequest = Null
End If
Set WinHttpReq = Nothing
End Function
%>
Let me know if this works for you.
After you grab the http response successfully, take a look at these webpages to get started with xml parsing:
http://msdn.microsoft.com/library/en-us/xmlsdk30/htm/xmmscxmlreference.asp
http://www.devguru.com/Technologies/xmldom/quickref/xmldom_intro.html
http://www.topxml.com/dom/default.asp
http://msdn.microsoft.com/library/en-us/xmlsdk30/htm/xmmscxmlreference.asp
http://www.devguru.com/Technologies/xmldom/quickref/xmldom_intro.html
http://www.topxml.com/dom/default.asp
After re-reading your question, I guess you have no problem with parsing the XML, please just ignore the previous comment. :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Function GetHTML(strURL)
Dim objXMLHTTP, strReturn
Set objXMLHTTP = Server.CreateObject("MSXML
objXMLHTTP.Open "GET", strURL, False
objXMLHTTP.Send
strReturn = objXMLHTTP.responseText
Set objXMLHTTP = Nothing
GetHTML = strReturn
End Function
FtB