Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read xml file 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
428
IT
How to get all node values, from that file?



<?xml version="1.0" encoding="utf-8"?><Response xmlns:xsd=" xmlns:xsi=" xmlns=" © 2023 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright><BrandLogoUri> Provinciale Quarantasette 27, 89818 Capistrano Vibo Valentia, Italy</Name><Point><Latitude>38.6857407</Latitude><Longitude>16.2937848</Longitude></Point><BoundingBox><SouthLatitude>38.68187798242932</SouthLatitude><WestLongitude>16.287187176966889</WestLongitude><NorthLatitude>38.689603417570673</NorthLatitude><EastLongitude>16.300382423033113</EastLongitude></BoundingBox><EntityType>Address</EntityType><Address><AddressLine>Strada Provinciale Quarantasette 27</AddressLine><AdminDistrict>Calabria</AdminDistrict><AdminDistrict2>Vibo Valentia</AdminDistrict2><CountryRegion>Italy</CountryRegion><FormattedAddress>Strada Provinciale Quarantasette 27, 89818 Capistrano Vibo Valentia, Italy</FormattedAddress><Locality>Capistrano</Locality><PostalCode>89818</PostalCode><Intersection><BaseStreet>Strada Provinciale Quarantasette</BaseStreet><SecondaryStreet1>Via Dante Alighieri</SecondaryStreet1><IntersectionType>Near</IntersectionType><DisplayName>Strada Provinciale Quarantasette and Via Dante Alighieri</DisplayName></Intersection></Address><Confidence>High</Confidence><MatchCode>Good</MatchCode><GeocodePoint><Latitude>38.6857407</Latitude><Longitude>16.2937848</Longitude><CalculationMethod>Rooftop</CalculationMethod><UsageType>Display</UsageType></GeocodePoint></Location></Resources></ResourceSet></ResourceSets></Response>
 
Here's one way, provided without explanation or support

Code:
[COLOR=blue]Option Explicit
Public depth as long

Public Sub sal21_101()
    Dim myDOM As DOMDocument
    Dim myItem As IXMLDOMElement
    Dim mynode As IXMLDOMElement
    
    Set myDOM = New DOMDocument
    myDOM.Load "d:\downloads\deleteme\bingmap.txt"
    NodeDive myDOM.getElementsByTagName("Location").Item(0)

End Sub

Public Sub NodeDive(aNode)
    Dim mynode
    
    depth = depth + 1
    If aNode.ChildNodes.Length > 0 And TypeName(aNode.ChildNodes) = "IXMLDOMNodeList" Then
        Debug.Print
        Debug.Print Space(depth * 4); aNode.nodeName; ": ";
        For Each mynode In aNode.ChildNodes
            NodeDive mynode
        Next
    Else
        Debug.Print aNode.Text;
    End If
    depth = depth - 1
End Sub
[/color]
 
That almost certainly means that there is an error in your XML file (and there is, if you are using the same one you attached in the OP).

And the error means the XML is not loaded. Which means that aNode is nothing.

But I'm going to leave you to figure that out. Here's a clue. UTF-8
 
I have covered reading and parsing (simple) json files with you at least twice in the past.

But here goes again. Be warned, this particular implementation only works with the example json file you have provided, it is not generic.

Code:
[COLOR=blue]Public Sub JSONDecode(JSONString)
    Dim Items As Object
    Dim itm As Object
    
    With CreateObject("ScriptControl")
        .Language = "JScript"
        Set Items = .Eval("(" + JSONString + ")")
        For Each itm In Items
            Debug.Print itm.codice
            Debug.Print itm.nome
            Debug.Print itm.codiceCatastale
            Debug.Print itm.cap
            Debug.Print itm.prefisso
            Debug.Print itm.provincia.nome, itm.provincia.regione
            Debug.Print itm.email
            Debug.Print itm.pec
            Debug.Print itm.telefono
            Debug.Print itm.fax
            Debug.Print itm.coordinate.lat, itm.coordinate.lng
            Debug.Print
        Next
    End With
End Sub[/color]

 
Not sure what the value is of suggesting using a solution in a completely different language, given that a) this is a VB6 forum, and b) a perfectly good VB6 solution for reading XML requested in the OP
 
The value? Just the 'plug' for his Company - see his profile.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top