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
<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://ift.tt/Vvf22j", "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
No comments:
Post a Comment