PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
oleobject loo_Xml
integer i
integer j
integer k
oleobject loo_SbValue
integer li_BAutoCreate
integer n
integer li_ACount
integer li_BCount
integer li_CCount
// Note: This example requires Chilkat v9.5.0.64 or later.
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
destroy loo_Xml
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Xml.Tag = "tripleNested"
i = 0
j = 0
k = 0
loo_SbValue = create oleobject
li_rc = loo_SbValue.ConnectToNewObject("Chilkat.StringBuilder")
li_BAutoCreate = 1
do while i < 3
loo_Xml.I = i
j = 0
do while j < 4
loo_Xml.J = j
k = 0
do while k < 2
loo_Xml.K = k
n = i * 100 + j * 10 + k
loo_SbValue.Clear()
loo_SbValue.AppendInt(n)
loo_Xml.UpdateAt("a[i]|b[j]|c[k]",li_BAutoCreate,loo_SbValue.GetAsString())
k = k + 1
loop
j = j + 1
loop
i = i + 1
loop
Write-Debug loo_Xml.GetXml()
// 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.
i = 0
li_ACount = loo_Xml.NumChildren
do while i < li_ACount
loo_Xml.I = i
j = 0
li_BCount = loo_Xml.NumChildrenAt("a[i]")
do while j < li_BCount
loo_Xml.J = j
k = 0
li_CCount = loo_Xml.NumChildrenAt("a[i]|b[j]")
do while k < li_CCount
loo_Xml.K = k
Write-Debug string(i) + ", " + string(j) + ", " + string(k) + ": " + string(loo_Xml.GetChildIntValue("a[i]|b[j]|c[k]"))
k = k + 1
loop
j = j + 1
loop
i = i + 1
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
//
destroy loo_Xml
destroy loo_SbValue