check error

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

check error

Post by sal21 »

I use thei code to find in a XML nodes:

Code: Select all

....

    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.

User avatar
HansV
Administrator
Posts: 78235
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: check error

Post by HansV »

Replace the line

Code: Select all

        STRADA = UCase(GetFirstNamedNode("AddressLine", nodes).Text)
with

Code: Select all

        Dim TheNode
        Set TheNode = GetFirstNamedNode("AddressLine", nodes)
        If TheNode Is Nothing Then
            Exit Sub
        End If
        STRADA = UCase(TheNode.Text)
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: check error

Post by sal21 »

HansV wrote:
03 Jun 2022, 09:39
Replace the line

Code: Select all

        STRADA = UCase(GetFirstNamedNode("AddressLine", nodes).Text)
with

Code: Select all

        Dim TheNode
        Set TheNode = GetFirstNamedNode("AddressLine", nodes)
        If TheNode Is Nothing Then
            Exit Sub
        End If
        STRADA = UCase(TheNode.Text)
as usual NO HAVE a WORS!
Work perfect.
Tks bro

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: check error

Post by sal21 »

HansV wrote:
03 Jun 2022, 09:39
Replace the line

Code: Select all

        STRADA = UCase(GetFirstNamedNode("AddressLine", nodes).Text)
with

Code: Select all

        Dim TheNode
        Set TheNode = GetFirstNamedNode("AddressLine", nodes)
        If TheNode Is Nothing Then
            Exit Sub
        End If
        STRADA = UCase(TheNode.Text)
bro...

i use this code for xml output in txt:

Code: Select all


XMLQUERY = "http://dev.virtualearth.net/REST/v1/Locations/" & LAT & "," & LNG & "?o=xml&C=IT&key=" & BINGKEY

'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
but the output is only in one line.

attached the output txt, and i need the output in image
You do not have the required permissions to view the files attached to this post.

User avatar
SpeakEasy
4StarLounger
Posts: 535
Joined: 27 Jun 2021, 10:46

Re: check error

Post by SpeakEasy »

>i need the output in image

Might I ask why?

(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)

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: check error

Post by sal21 »

SpeakEasy wrote:
03 Jun 2022, 18:14
>i need the output in image

Might I ask why?

(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

User avatar
SpeakEasy
4StarLounger
Posts: 535
Joined: 27 Jun 2021, 10:46

Re: check error

Post by SpeakEasy »

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):

Code: Select all

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

User avatar
SpeakEasy
4StarLounger
Posts: 535
Joined: 27 Jun 2021, 10:46

Re: check error

Post by SpeakEasy »

Hello? Was this of any use?

User avatar
sal21
PlatinumLounger
Posts: 4334
Joined: 26 Apr 2010, 17:36

Re: check error

Post by sal21 »

SpeakEasy wrote:
13 Jun 2022, 17:08
Hello? Was this of any use?
Sorry bro but im busy with family.