Archived Forum Post

Index of archived forum posts

Question:

XML Loop into child of a child

Sep 14 '15 at 10:16

I need to process some data I am getting in an XML file. It is going fine processing 1st level childs but I am getting lost how to get a step lower. The xml file has got a list of properties (real estate) each property has got an undefined number of pictures and features. You can see a sample file here http://www.corobori.com/sos/test.xml

Find below my code retrieving part of the xml file, see "how to do from here ?", this is where I hit a snag

        Dim prop As Chilkat.Xml
        Dim fotos As Chilkat.Xml

        If Not IsNothing(xml0) Then

            Dim n As Long
            Dim iFoto As Long
            Dim i As Long

            child = xml0.FindChild("corredor")
            If (child Is Nothing) Then
            Else
                Response.Write("Content = " & child.Content)
            End If
            child = xml0.FindChild("clave")
            If (child Is Nothing) Then

            Else
                Response.Write("Content = " & child.Content)
            End If

            n = xml0.NumChildrenHavingTag("propiedad")
            For i = 0 To n - 1

                prop = xml0.GetNthChildWithTag("propiedad", i)

                ' Codigo Interno fine 
                Response.Write(prop.GetChildContent("id") & "<br>")

                iFoto = prop.NumChildrenHavingTag("fotos")
                Response.Write("Fotos: " & iFoto & "<br>")

                ' how to do from here ? 
                ' fotos = prop.GetNthChildWithTag("fotos", 1)

            Next

        End If

Accepted Answer

Change this:

                ' how to do from here ? 
                ' fotos = prop.GetNthChildWithTag("fotos", 1)
To this:
                ' how to do from here ? 
                fotos = prop.GetNthChildWithTag("fotos", 0)
The 1st child is at index 0. All of Chilkat always uses 0-based counting. Whenever there is an "index" in a method call, it is 0-based meaning that the 1st item is at index 0.


Answer

Thanks a lot, this solved my issue !