我收到的XML响应包含一些如下所示的地理位置数据:
<markers>
<marker positionid="1" latitude="35.85149666666667" longitude="-86.47591333333334" time="2015-02-14 14:16:35" uniqueid="sheaphone" speed="3.89"/>
<marker positionid="32" latitude="35.85128666666667" longitude="-86.47599333333334" time="2015-02-14 14:47:58" uniqueid="medic 13" speed="0"/>
</markers>
这是我目前的代码,但我继续阅读第一条记录两次,而我似乎无法循环到第二条记录。我已经对这篇文章进行了任何循环尝试。最终结果是我需要在表中插入或更新记录,如果我可以让节点正确循环,我可以这样做。我正在使用Access 2010和2013。
Dim xmlDoc As MSXML2.DOMDocument
Dim strUrl As String
Dim lngPositionID As Long
Dim dblLatitude As Double
Dim dblLongitude As Double
Dim dtTime As Date
Dim strUniqueID As String
Dim lngSpeed As Long
Dim strLength As String
Dim nodeCurrent As MSXML2.IXMLDOMNode
strUrl = REMOVED FOR PRIVACY
Set xmlDoc = New MSXML2.DOMDocument
xmlDoc.async = False
xmlDoc.Load strUrl
lngPositionID = xmlDoc.selectSingleNode("//markers/marker").Attributes.getNamedItem("positionid").nodeValue
dblLatitude = xmlDoc.selectSingleNode("//markers/marker").Attributes.getNamedItem("latitude").nodeValue
dblLongitude = xmlDoc.selectSingleNode("//markers/marker").Attributes.getNamedItem("longitude").nodeValue
dtTime = xmlDoc.selectSingleNode("//markers/marker").Attributes.getNamedItem("time").nodeValue
strUniqueID = xmlDoc.selectSingleNode("//markers/marker").Attributes.getNamedItem("uniqueid").nodeValue
lngSpeed = xmlDoc.selectSingleNode("//markers/marker").Attributes.getNamedItem("speed").nodeValue
Debug.Print "PositionID: " & lngPositionID & " Latitude: " & dblLatitude & " Longitude: " & dblLongitude & " Time: " & dtTime & " UniqueID: " & strUniqueID & " Speed: " & lngSpeed
这是通过当前的调试结果。在进行任何循环尝试时,我最多只获得了这一行。
PositionID: 1 Latitude: 35.8514966666667 Longitude: -86.4759133333333 Time: 2/14/2015 2:16:35 PM UniqueID: sheaphone Speed: 4