I'm building a site on a Windows Server with ASP enabled. I need to retrieve an XML document from another server and return a value in that document. The xml file is small - only one node with a text value. I just need to return that text value. I've never worked with ASP before, and Googling around has led me to some code examples, but nothing that works so far. Here's what I've got, which gives me a 500:
<%
Dim URL, objXML
URL = "http://someserver.com/xml"
Set objXML = Server.CreateObject("MSXML2.DOMDocument.4.0")
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
Set oRoot = objXML.selectSingleNode("//xml/response")
var = oRoot.text
set objXML = nothing
%>
<%= var %>
===========
Update:
Yes, you're exactly correct about my XML. Just one node with a value. Based on your comments, I edited my asp code to:
<%
Dim URL, objXML, value
URL = "http://someserver.com/xml"
Set objXML = Server.CreateObject("MSXML2.DOMDocument.6.0")
objXML.setProperty "ServerHTTPRequest", True
objXML.async = False
objXML.Load URL
Response.Write objXML.parseError.reason
value = objXML.documentElement.Text
set objXML = nothing
%>
<%= value %>
Which is still returning a 500. How do I go about debugging ASP? Is there some way to turn on detailed error reporting?
Debugging ASP is not as pleasant as you might be used to. This should help though:
It could be that you have a 500 error handler page on the server you are using (assuming you are not running local). In which case you will have to modify the 500 page if you can so it gives you more details of the real error (see http://www.w3schools.com/ASP/asp_ref_error.asp). If you develop locally though you tend to get all the juicy details.
I wrote this function:
As Pete Duncanson said, the first thing to try is to untick "Show friendly error messages".
If you are still getting 500 errors they are probably coming from IIS (you can probably tell by looking at them). I have put up a guide for enabling error messages on IIS7 here if you need that.
Change line 4 of your original snippet to
and line 14 to
and you should be fine (assuming your xml is as AnthonyWJones describes).
Your original //xml/response would get the text from a document that looked like this
Classic ASP debugging is a nasty topic to which millions of otherwise fine brain cells have been sacrificed over the years. Even with tools intended for developing and/or supporting classic ASP, enabling debugging can be tricky.
If your effort is a relatively small one-time thing, as your question sort of suggests, then it probably doesn't make sense to spend a lot of time setting up and configuring an advanced ASP/script debugging environment. Instead, as per Pete Duncanson's answer, simply inject some Response.Write statements into your script and figure out where and why it is failing the old fashioned way. However, the one thing Pete didn't point out is that you'll need to turn on a VBScript error handler (error swallower, actually) in order to avoid tossing an unhandled exception, resulting in IIS serving you a 500.
I setup and ran the following code and it worked fine (i.e., no errors). The XML URL pointed to a simple file in the same virtual directory on the local machine as the ASP page and it contained the XML found in AnthonyWJones's answer. (Btw, I have no idea how you got your VBScript so well formatted in the original question, so my copy looks pretty bad.)
Open this in IE or Firefox and if everything goes well you should see this:
Of course, everything isn't going to go well, otherwise you wouldn't be here, in which case you should see the error details appear at some point following one of the Response.Write values. Here's some additional information about the VBScript Err object.
Good luck!
Assuming your Xml is in fact:-
Try using:-
BTW,
When you call methods from which you are not returning a value you do not need the brackets:-
Also if this is your server, install MSXML6 and use MSXML2.DOMDocument.6.0. IF this is not your server use MSXML3.DOMDocument.3.0