....
Dim APICall As String
Dim Query As String
Dim strKey As String
Dim T As Long, XMLQUERY As String
Dim myXML As New MSXML2.DOMDocument
Dim nodes As IXMLDOMSelection
XMLQUERY = "http://dev.virtualearth.net/REST/v1/Locations/" & LAT & "," & LNG & "?o=xml&C=IT&key=" & BINGKEY
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", XMLQUERY, False
.send
Do While myXML.ReadyState <> READYSTATE_COMPLETE
Sleep (100)
Loop
'TEST XML
'Dim OBJ As Object
'Dim TESTO As String
'Dim TEMP As String
'Set OBJ = CreateObject("InetCtls.Inet")
'TESTO = OBJ.OpenURL(XMLQUERY)
'TEMP = (TESTO)
'Open "C:\SERVIZIO\FileXML.XML" For Output As #1
'Print #1, TEMP
'Close #1
'Set OBJ = Nothing
'TEST XML
myXML.loadXML .responseText 'raw xml
Set nodes = myXML.selectNodes("//*")
...
STRADA = UCase(GetFirstNamedNode("AddressLine", nodes).Text)
...
end with
Private Function GetFirstNamedNode(myNode As String, myNodes As IXMLDOMSelection) As IXMLDOMElement
Dim seeknode As IXMLDOMElement
NRLINE = 0
For Each seeknode In myNodes
If seeknode.nodeName = myNode Then
Set GetFirstNamedNode = seeknode
NRLINE = 1
Exit For
End If
Next
'If seeknode Is Nothing Then Stop
End Function
.....
only a prob... if the code dont find the node AddressLine, to the end of function have the error in image...
how to check?
You do not have the required permissions to view the files attached to this post.
(simplest way to get pretty much that is just to open the XML file in a recentish browser (e.g. IE, Edge, Chrome; indeed your jpg above seems to be the way Edge displays it), but I suspect you don't think that is something you want to do. Do you really need all the different, specific colours, the specific tabbing, the specific fonts? I ask because different applications that provide pretty XML displays all do it differently, since XML itself is a metalanguage with no format of its own)
(simplest way to get pretty much that is just to open the XML file in a recentish browser (e.g. IE, Edge, Chrome; indeed your jpg above seems to be the way Edge displays it), but I suspect you don't think that is something you want to do. Do you really need all the different, specific colours, the specific tabbing, the specific fonts? I ask because different applications that provide pretty XML displays all do it differently, since XML itself is a metalanguage with no format of its own)
NOT ALL COLOR!
but i need the formated text line by line
Excellent, in which case we can leverage the fact that MSXML2 (which you are already using) has classes with the ability to parse raw XML into a prettier version that we humans like (about 50% of the following code is comments, so it is actually pretty short):
Public Sub PrettyXMLExample(myXMLString As String)
Dim objXML As New MSXML2.DOMDocument
Dim xmlReader As New MSXML2.SAXXMLReader
Dim xmlWriter As New MSXML2.MXXMLWriter
If objXML.LoadXML(myXMLString) Then
With xmlWriter
.omitXMLDeclaration = True
.indent = True
End With
With xmlReader
Set .contentHandler = xmlWriter
Set .dtdHandler = xmlWriter
Set .errorHandler = xmlWriter
' Now pass the DOM through the SAX handler, and it will call the xmlWriter
.Parse objXML
End With
'At this point xmlWriter.output has the prettified version of the raw XML
' So we can now do what we like with it
' e.g. stick it in a textbox:
Text2.Text = xmlWriter.output
' or we could use file functions to write it to a file, or Split it
' or load the pretty version back into objXML ansd use DomDocument's
' ability to output direct to a file as shown in the 2 commented out lines below:
' objXML.LoadXML xmlWriter.output
' objXML.Save "d:\downloads\deleteme\output.xml" ' your output file goes here
Else
' XML failed to load
End If
End Sub