Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Node.js) Demonstrate the XML I, J, and K PropertiesDemonstrates 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.
var os = require('os'); if (os.platform() == 'win32') { if (os.arch() == 'ia32') { var chilkat = require('@chilkat/ck-node21-win-ia32'); } else { var chilkat = require('@chilkat/ck-node21-win64'); } } else if (os.platform() == 'linux') { if (os.arch() == 'arm') { var chilkat = require('@chilkat/ck-node21-arm'); } else if (os.arch() == 'x86') { var chilkat = require('@chilkat/ck-node21-linux32'); } else { var chilkat = require('@chilkat/ck-node21-linux64'); } } else if (os.platform() == 'darwin') { if (os.arch() == 'arm64') { var chilkat = require('@chilkat/ck-node21-mac-m1'); } else { var chilkat = require('@chilkat/ck-node21-macosx'); } } function chilkatExample() { // Note: This example requires Chilkat v9.5.0.64 or later. var xml = new chilkat.Xml(); xml.Tag = "tripleNested"; var i = 0; var j = 0; var k = 0; var sbValue = new chilkat.StringBuilder(); var bAutoCreate = true; while (i < 3) { xml.I = i; j = 0; while (j < 4) { xml.J = j; k = 0; while (k < 2) { xml.K = k; var n = i * 100+j * 10+k; sbValue.Clear(); sbValue.AppendInt(n); xml.UpdateAt("a[i]|b[j]|c[k]",bAutoCreate,sbValue.GetAsString()); k = k+1; } j = j+1; } i = i+1; } console.log(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; var aCount = xml.NumChildren; while (i < aCount) { xml.I = i; j = 0; var bCount = xml.NumChildrenAt("a[i]"); while (j < bCount) { xml.J = j; k = 0; var cCount = xml.NumChildrenAt("a[i]|b[j]"); while (k < cCount) { xml.K = k; console.log(i + ", " + j + ", " + k + ": " + xml.GetChildIntValue("a[i]|b[j]|c[k]")); k = k+1; } j = j+1; } i = i+1; } // 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 // } chilkatExample(); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.