views:

38

answers:

2

Hi Everyone,

I am trying to parse a single XML entry with no name in ASP classic and having issues getting it to resolve to an object?

Here is what I am trying:

result = xmlDoc.selectSingleNode("//Boolean")

I have also tried:

result = xmlDoc.selectSingleNode("//Boolean").Attributes.Text

Neither of them return an object, this is my first time working with XML and I haven't got a clue how to get an object without a name.

Here is the XML results file:

<boolean>true</boolean>

And here is the error:

Microsoft VBScript runtime  error '800a01a8'

Object required: 'xmlDoc.selectSingleNode(...)' 

How xmldoc is being populated:

set xmlDoc = createObject("MSXML2.DOMDocument")
xmlDoc.async = False
xmlDoc.setProperty "ServerHTTPRequest", true


url = "http://localhost:81/api/logging/Service.svc/xml/LogEvent?"

//Create the http string
url = url & "sessionId=" & sessionId
url = url & "source=" & source
url = url & "action=" & action
url = url & "parameters=" & parameters

xmlDoc.load(url)

result = xmlDoc.selectSingleNode("//Boolean")
+2  A: 

XML is case sensitive, and so is XPath. Try:

Set result = xmlDoc.selectSingleNode("//boolean")

Also, note the Set statement, it is necessary for object assignments.

Further, you must check if the select operation succeeded before going on:

If Not result Is Nothing Then
  boolValue = CBool(result.nodeValue)
End If 

CBool() understands "true" and "false" but throws a type mismatch error for other strings.

For earlier MSXML Versions you also need to set the selection language to XPath at first.

xmlDoc.setProperty("SelectionLanguage", "XPath");
Tomalak
A: 

Here is what I ended up doing -- instead of using the DOMDocument HTTPRequest I used Msxml2.ServerXMLHTTP. For whatever reason I couldn't use responseXML as it wasn't being returned as XML -- but responseText worked just fine as I will always be returning "true" or "false" in the boolean value.

Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")

'Build the url string
url = url & "pki=" & LOGGING_PKI
url = url & "&sessionId=" & sessionId
url = url & "&source=" & source
url = url & "&action=" & action
'Clean parameters string
parameters = Replace(parameters,"&", "%26")
url = url & "&parameters=" & parameters

' Send http request
objXmlHttp.open "GET", url, False
objXmlHttp.send

'Check response
strHTML = objXmlHttp.responseText

Set objXmlHttp = Nothing

'If responseText = true then logging was successful
if instr(strHTML, "true") <> "" then
    logEvent = true
else
    logEvent = false
end if
Miva
@Miva: You definitely should use `Server.URLEncode()` on all values in the "Build the url string" section. Also, dump the custom `Replace()` you're doing and use `Server.URLEncode()` on `parameters` again. That's the only bug-free way of doing it. The `responseXML` property was unavailable because most certainly the response was not sent with an XML Content-Type header. Fix this and it will work.
Tomalak