Sample code for 30+ languages & platforms
DataFlex

Demonstrate the XML I, J, and K Properties

See more XML Examples

Demonstrates the XML I, J, and K properties. These properties can be used in paths to access the I'th, J'th, or K'th child in a path. Three indexing properties are provided to allow for triple-nested loops using this feature.

Note: This example requires Chilkat v9.5.0.64 or later.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoXml
    Integer i
    Integer j
    Integer k
    Handle hoSbValue
    Boolean iBAutoCreate
    Integer n
    Boolean iSuccess
    Integer iACount
    Integer iBCount
    Integer iCCount
    String sTemp1
    Integer iTemp1

    // Note: This example requires Chilkat v9.5.0.64 or later.

    Get Create (RefClass(cComChilkatXml)) To hoXml
    If (Not(IsComObjectCreated(hoXml))) Begin
        Send CreateComObject of hoXml
    End

    Set ComTag Of hoXml To "tripleNested"

    Move 0 To i
    Move 0 To j
    Move 0 To k

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbValue
    If (Not(IsComObjectCreated(hoSbValue))) Begin
        Send CreateComObject of hoSbValue
    End
    Move True To iBAutoCreate

    While (i < 3)
        Set ComI Of hoXml To i
        Move 0 To j
        While (j < 4)
            Set ComJ Of hoXml To j
            Move 0 To k
            While (k < 2)
                Set ComK Of hoXml To k

                Move (i * 100 + j * 10 + k) To n
                Send ComClear To hoSbValue
                Get ComAppendInt Of hoSbValue n To iSuccess

                Get ComGetAsString Of hoSbValue To sTemp1
                Get ComUpdateAt Of hoXml "a[i]|b[j]|c[k]" iBAutoCreate sTemp1 To iSuccess
                Move (k + 1) To k
            Loop

            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    Get ComGetXml Of hoXml To sTemp1
    Showln sTemp1

    // This is the XML
    // See below for code showing how to parse it..

    // 	<?xml version="1.0" encoding="utf-8" ?>
    // 	<tripleNested>
    // 	    <a>
    // 	        <b>
    // 	            <c>0</c>
    // 	            <c>1</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>10</c>
    // 	            <c>11</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>20</c>
    // 	            <c>21</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>30</c>
    // 	            <c>31</c>
    // 	        </b>
    // 	    </a>
    // 	    <a>
    // 	        <b>
    // 	            <c>100</c>
    // 	            <c>101</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>110</c>
    // 	            <c>111</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>120</c>
    // 	            <c>121</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>130</c>
    // 	            <c>131</c>
    // 	        </b>
    // 	    </a>
    // 	    <a>
    // 	        <b>
    // 	            <c>200</c>
    // 	            <c>201</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>210</c>
    // 	            <c>211</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>220</c>
    // 	            <c>221</c>
    // 	        </b>
    // 	        <b>
    // 	            <c>230</c>
    // 	            <c>231</c>
    // 	        </b>
    // 	    </a>
    // 	</tripleNested>
    // 

    // Parse the XML, without needing to know the number of children.
    // That can be discovered with the NumChildrenAt method.

    Move 0 To i
    Get ComNumChildren Of hoXml To iACount
    While (i < iACount)
        Set ComI Of hoXml To i
        Move 0 To j
        Get ComNumChildrenAt Of hoXml "a[i]" To iBCount
        While (j < iBCount)
            Set ComJ Of hoXml To j
            Move 0 To k
            Get ComNumChildrenAt Of hoXml "a[i]|b[j]" To iCCount
            While (k < iCCount)
                Set ComK Of hoXml To k
                Get ComGetChildIntValue Of hoXml "a[i]|b[j]|c[k]" To iTemp1
                Showln i ", " j ", " k ": " iTemp1
                Move (k + 1) To k
            Loop

            Move (j + 1) To j
        Loop

        Move (i + 1) To i
    Loop

    // Output:

    // 	0, 0, 0: 0
    // 	0, 0, 1: 1
    // 	0, 1, 0: 10
    // 	0, 1, 1: 11
    // 	0, 2, 0: 20
    // 	0, 2, 1: 21
    // 	0, 3, 0: 30
    // 	0, 3, 1: 31
    // 	1, 0, 0: 100
    // 	1, 0, 1: 101
    // 	1, 1, 0: 110
    // 	1, 1, 1: 111
    // 	1, 2, 0: 120
    // 	1, 2, 1: 121
    // 	1, 3, 0: 130
    // 	1, 3, 1: 131
    // 	2, 0, 0: 200
    // 	2, 0, 1: 201
    // 	2, 1, 0: 210
    // 	2, 1, 1: 211
    // 	2, 2, 0: 220
    // 	2, 2, 1: 221
    // 	2, 3, 0: 230
    // 	2, 3, 1: 231
    // 


End_Procedure