Having a small issue here, I am working on a legacy Classic ASP application for a customer and have the need to pull data from an XML file but I cannot get the value of a single node, my code just returns nothing.
I have and am able to pull all data from the XML file without any problems.
XML file
<?xml version="1.0" encoding="UTF-8"?>
<Devices-Detail-Response>
<PollCount>36593</PollCount>
<DevicesConnected>1</DevicesConnected>
<LoopTime>1.031</LoopTime>
<DataErrors>0</DataErrors>
<DeviceName>OW_SERVER-Enet</DeviceName>
<HostName>EDSOWSERVER</HostName>
<MACAddress>00:50:C2:91:B3:9C</MACAddress>
<owd_DS18B20 Description="Programmable resolution thermometer">
<Name>DS18B20</Name>
<Family>28</Family>
<ROMId>2D0000023C519A28</ROMId>
<Health>7</Health>
<RawData>61014B467FFF0F1002FF000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000</RawData>
<PrimaryValue>22.0625 Deg C</PrimaryValue>
<Temperature Units="Centigrade">22.0625</Temperature>
<UserByte1 Writable="True">75</UserByte1>
<UserByte2 Writable="True">70</UserByte2>
<Resolution>12</Resolution>
<PowerSource>255</PowerSource>
</owd_DS18B20>
</Devices-Detail-Response>
xml-text.asp file
<%
Option Explicit
Response.Write GetTemperature("http://192.168.1.85/details.xml", "2D0000023C519A28")
Function GetTemperature(strXMLFile, strName)
Dim objXML : Set objXML = CreateObject("Msxml2.DOMDocument.6.0")
objXML.async = False
objXML.SetProperty "SelectionLanguage", "XPath"
objXML.SetProperty "ServerHTTPRequest", True
objXML.load(strXMLFile)
''// enclose in single- or double quotes accordingly
If InStr(strName, "'") > 0 And InStr(strName, """") = 0 Then
strName = """" & strName & """"
ElseIf InStr(strName, "'") = 0 And InStr(strName, """") > 0 Then
strName = "'" & strName & "'"
Else
''// both single and double quotes in a string are unsupported
strName = "''"
End If
Dim strXPath : strXPath = "/Devices-Detail-Response/owd_DS18B20[ROMId=" & strName & "]/Temperature"
Dim objNode : Set objNode = objXML.documentElement.selectSingleNode(strXPath)
If Not objNode Is Nothing Then
value = objNode.text
End If
End Function
%>
The value = objNode.text
simply returns nothing and if I move back along the XPath I still get nothing.
It's late and I know I am missing something simple ?!?
Cheers,
Ozzie
UPDATE: OK a little update here, if i do the following:
Dim xmlSensor
For Each xmlSensor In objXML.documentElement.selectNodes("owd_DS18B20")
Dim romID : romID = xmlSensor.selectSingleNode("ROMId").text
Dim temperature : temperature = xmlSensor.selectSingleNode("Temperature").text
Response.Write Server.HTMLEncode(romID) & "<br />"
Response.Write Server.HTMLEncode(temperature) & "<br /><br />"
Next
I get the required values, the issue is there could be upto 24 sensors linked and the ROMId is the unique identifier so we really need to filter on this so the issue must be to do with the XPATH string I think.