Link to home
Start Free TrialLog in
Avatar of vcgDevelopers
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
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Any luck with this:

Function GetHTML(strURL)
      Dim objXMLHTTP, strReturn
      Set objXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
      objXMLHTTP.Open "GET", strURL, False
      objXMLHTTP.Send
      strReturn = objXMLHTTP.responseText
      Set objXMLHTTP = Nothing
      GetHTML = strReturn
End Function

FtB
Avatar of vcgDevelopers
vcgDevelopers

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
I am not sure. If you would like to try this with my site to see, use http://www.FaifieldConsulting.com a shot.

FtB

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
I thought that did return tag names. Hang on a few minutes...

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("MSXML2.ServerXMLHTTP")
     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"))

 %>
What is the best way to grab the return, xsl stylesheets?  I may have to run out and buy another book..
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.WinHttpRequest.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.
After re-reading your question, I guess you have no problem with parsing the XML, please just ignore the previous comment. :-)
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial