For some reason the text values are concatenating but I want them to be broken out by the Node name and value. I put notes in the code. The Code DOES work just not how I need it.
<%url = "https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/ZPBUA1ZLXKLA00941?format=xml" ' add a BASE HREF tag Dim xmldoc dim xmlhttp Response.write "<BASE HREF='" & url & "'><P>" & url & "<P>" set xmlhttp = CreateObject("Microsoft.XMLHTTP") Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlhttp.open "GET", url, false xmlhttp.send "" 'response.write xmlhttp.responsetext xmlDoc.async = False bresult=xmlDoc.loadxml(xmlhttp.responsetext) State = "" ' WORKS ...Set NodeList = xmlDoc.getElementsByTagName("*") 'Set NodeList = xmlDoc.documentElement.selectNodes("/Response/*") 'Set NodeList = xmlDoc.documentElement.selectNodes("/Response/Results/*") Set NodeList = xmlDoc.documentElement.selectNodes("/Response/Results/DecodedVariable") 'Set NodeList = xmlDoc.documentElement.selectNodes("/Response/Results/DecodedVariable/*") For Each Node in NodeList 'I NEED SOME SORT OF LOGIC HERE If Node.tagName = "VariableId" Then ' response.write Node.tagName & "<br>" ' Do Something LOGIC End If 'I NEED SOME SORT OF LOGIC HERE 'If Node.tagName("VariableId") = 156 then 'End if response.write "TagName: " & Node.tagName & "<br>" response.write("Node.text :" & Node.text & "<br>") response.write("Node.baseName :" & Node.baseName & "<br>") response.write("Node.nodeName:" & Node.nodeName & "<br>") response.write("Node.nodeType:" & Node.nodeType & "<br>") response.write("Node.nodeValue:" & Node.nodeValue & "<br>") Next set xmlhttp = nothing%>
I am accessing the data you are looking for using, node.getElementsByTagName("VariableId").Item(0).Text
<%url = "https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/ZPBUA1ZLXKLA00941?format=xml" ' add a BASE HREF tag Dim xmldoc dim xmlhttp Response.write "<BASE HREF='" & url & "'><P>" & url & "<P>" set xmlhttp = CreateObject("Microsoft.XMLHTTP") Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlhttp.open "GET", url, false xmlhttp.send "" 'response.write xmlhttp.responsetext xmlDoc.async = False bresult=xmlDoc.loadxml(xmlhttp.responsetext) response.write bresult State = "" ' WORKS ...Set NodeList = xmlDoc.getElementsByTagName("*") 'Set NodeList = xmlDoc.documentElement.selectNodes("/Response/*") 'Set NodeList = xmlDoc.documentElement.selectNodes("/Response/Results/*") Set NodeList = xmlDoc.documentElement.selectNodes("/Response/Results/DecodedVariable") 'Set NodeList = xmlDoc.documentElement.selectNodes("/Response/Results/DecodedVariable/*") For Each Node in NodeList response.write "<hr>" 'I NEED SOME SORT OF LOGIC HERE If Node.tagName = "VariableId" Then ' response.write Node.tagName & "<br>" ' Do Something LOGIC End If 'I NEED SOME SORT OF LOGIC HERE 'If Node.tagName("VariableId") = 156 then 'End if response.write node.getElementsByTagName("VariableId").Item(0).Text &"<br>" VariableId = node.getElementsByTagName("VariableId").Item(0).Text if cint(VariableId) = 156 then response.write "********** FOUND ***********" end if 'response.write "TagName: " & Node.tagName & "<br>" 'response.write("Node.text :" & Node.text & "<br>") 'response.write("Node.baseName :" & Node.baseName & "<br>") 'response.write("Node.nodeName:" & Node.nodeName & "<br>") 'response.write("Node.nodeType:" & Node.nodeType & "<br>") 'response.write("Node.nodeValue:" & Node.nodeValue & "<br>") response.write "<hr>" Next set xmlhttp = nothing%>
Cause you don't parse the single elements. The .text property does return all text from the node. Thus you need to parse for the single values, e.g. something like
<% Sub OutputNode(ANode) Response.write "TagName: " & ANode.tagName & "<br>" Response.write("Node.text :" & ANode.text & "<br>") Response.write("Node.baseName :" & ANode.baseName & "<br>") Response.write("Node.nodeName:" & ANode.nodeName & "<br>") Response.write("Node.nodeType:" & ANode.nodeType & "<br>") Response.write("Node.nodeValue:" & ANode.nodeValue & "<br>") End Sub Sub ParseDocument(ADocument) For Each Node in ADocument.documentElement.selectNodes("/Response/Results/DecodedVariable") OutputNode Node.selectSingleNode("VariableId") OutputNode Node.selectSingleNode("Variable") OutputNode Node.selectSingleNode("ValueId") OutputNode Node.selectSingleNode("Value") Next End Sub Function RetrieveXml(AUrl) Dim xmldoc Dim xmlhttp Response.write "<BASE HREF='" & Aurl & "'><P>" & Aurl & "<P>" Set xmlhttp = CreateObject("Microsoft.XMLHTTP") Set xmlDoc = CreateObject("Microsoft.XMLDOM") xmlhttp.open "GET", AUrl, false xmlhttp.send "" xmlDoc.async = False xmlDoc.loadxml(xmlhttp.responsetext) Set xmlhttp = nothing Set RetrieveXml = xmlDoc End Function Dim url Dim document url = "https://vpic.nhtsa.dot.gov/api/vehicles/decodevin/ZPBUA1ZLXKLA00941?format=xml" document = RetrieveXml(url) ParseDocument document%>
Thanks Scott, but how do I get the node names and values from the child nodes of DecodedVariable? for example I can identify the VariableID below at 142 so if my logic find this, then I need to be able to get the Variable value too
I am accessing the data you are looking for using, node.getElementsByTagName(
Open in new window