-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxml_MeshDefReader_v4_.ms
350 lines (280 loc) · 7.6 KB
/
xml_MeshDefReader_v4_.ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
struct xmlStruct
(
isRoot = false,
rootName = undefined,
nodeName = undefined,
numChildren = 0,
children = #(),
parentName = undefined,
attribs = #(#(),#()),
depth = 0,
idx = 0,
parentIDX = #()
)
struct read_xml
(
str_xmlStruct,
report = false,
xmldoc,
docEle,
rootName = undefined,
rootChildrenIDX = 0,
rootChildrenIDX_2 = 0,
rootIDX = undefined,
depth = 0,
idx = 0,
depthArr = #(),
numRecurse = 0,
_xml_template = #(),
_xml = #(),
attribName,
attribValue,
attribN,
attribV,
--format indents for tree level
fn format_tabs depth = ( for i=1 to depth do format "\t" ),
fn get_Nested_def \
theNode =
(
attribN = undefined
attribV = undefined
--/*
for n=0 to theNode.attributes.count-1 do
(
attribN = theNode.attributes.itemof[n].name
attribV = theNode.attributes.itemof[n].value
rootP = getinisetting CONST_CONFIG_PATH "root" "rootpath" --get the rootpath from the ini
refPath = pathConfig.appendpath rootP attribV --construct the final path
format "attribN: %\n" attribN
format "attribV: %\n" attribV
--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
if attribN == "definition" AND (doesfileexist refPath) then
(
if (doesfileexist refPath) then
(
arrDef = #() --reset array
str_read_xml = read_xml()
str_read_xml.report = true
--read definition
arrDef = str_read_xml.main \
refPath \
str_read_xml._xml
--format "attribV:% \n" refPath
--Append VARIANT_MESH_REFERENCE_array arrDef
)
)
--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
)
--*/
),
--get the attributes
fn get_Attribs \
theNode \
xml_arr =
(
attribName = undefined
attribValue = undefined
for n=0 to theNode.attributes.count-1 do
(
attribName = theNode.attributes.itemof[n].name
attribValue = theNode.attributes.itemof[n].value
Append str_xmlStruct.attribs[1] attribName
Append str_xmlStruct.attribs[2] attribValue
if report then
(
--REPORT
----------------depth format
format_tabs depth
format " --m_attribName: %\n" attribName
----------------depth format
format_tabs depth
format " --m_attribValue: %\n" attribValue
)
)
),
--recurse function
fn recurse \
children \
xml_arr =
(
numRecurse += 1
----------------depth add
depth += 1
children = children.childnodes
childNum2 = undefined --the count of the child
childName = undefined
parentNode = undefined
parentName = undefined
for x=0 to children.count-1 do
(
------------------------------------------------------------------------------------
if x == 0 then
(
rootChildrenIDX_2 += 1
)
------------------------------------------------------------------------------------
child = children.itemof[x]
childNum2 = children.itemof[x].childnodes.count --the count of the child
childName = child.name
parentNode = child.parentNode
parentName = child.parentNode.name
----array append----
str_xmlStruct = xmlStruct() --create instance
str_xmlStruct.rootName = rootName
str_xmlStruct.numChildren = childNum2
str_xmlStruct.nodeName = childName
str_xmlStruct.parentName = parentName
str_xmlStruct.depth = depth
/*
--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
if childName == "VARIANT_MESH_REFERENCE" then
(
--get attribs
get_Nested_def \
child
)
--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//--//
--*/
Append str_xmlStruct.parentIDX rootIDX --always zero, this is the root index
Append str_xmlStruct.parentIDX idx --children directly under root
Append str_xmlStruct.parentIDX rootChildrenIDX
if depth > 2 then
(
Append str_xmlStruct.parentIDX (rootChildrenIDX_2) --idx
Append str_xmlStruct.parentIDX (x+1) --children count
)
if report then
(
--REPORT
----------------depth format
format_tabs depth
format "\n"
--print tree index level
format_tabs depth
for d=1 to depth do
(
format "%." str_xmlStruct.parentIDX[d]
)
--format the name of the node
format "%. Name: %\t(parent: %)\n" (x+1) childName parentName
)
--get attribs
get_Attribs \
child \
xml_arr
Append xml_arr str_xmlStruct
--the recurse 2
recurse \
child \
xml_arr
)
----------------depth substract
depth -= 1
),
fn csharp_assembly \
xmlPath =
(
--------------------------------Create the dotNet xmlDoc----------------------------
--Load the xml assemply
dotNet.loadAssembly "system.xml"
--Create an xml document object.
xmldoc = dotnetobject "System.XML.XMLDocument"
--This is the Root of the XML
if template != "" then
(
xmldoc.Load xmlPath
)
return xmldoc.documentElement
),
fn main \
xmlPath \
xml_arr =
(
docEle = (csharp_assembly xmlPath)
--read the root and get inside the xml to read the rest via the recurse function
if docEle !=undefined then
(
xml_arr = #()
rootIDX = 0
if report then
(
rootName = docEle.name
format "%. Root: %\n" rootIDX rootName --->>>
)
---- array append ( this is the root - only one ofcourse) ----
str_xmlStruct = xmlStruct()
str_xmlStruct.rootName = rootName
str_xmlStruct.isRoot = true
Append str_xmlStruct.parentIDX rootIDX
Append xml_arr str_xmlStruct
--first pass the root to get its children (if there arent any children to the root, we cannot go in here)
if docEle.childnodes.count > 0 then
(
----------------depthadd
depth += 1
--recurse through each of the root children -- it will go as deep as it needs to
for n=0 to docEle.childnodes.count-1 do
(
child = docEle.childnodes.itemof[n]
childName = child.name
if report then
(
--REPORT
----------------depth format
format_tabs depth
format "\n"
----------------depth format
format_tabs depth
format "%.%. Name: %\n" rootIDX (n+1) childName --->>>
)
idx += 1
----array append----
str_xmlStruct = xmlStruct()
str_xmlStruct.nodeName = childName
str_xmlStruct.numChildren = docEle.childnodes.count
Append str_xmlStruct.children childName
str_xmlStruct.parentName = child.parentNode.name
str_xmlStruct.depth = depth
Append str_xmlStruct.parentIDX rootIDX
Append str_xmlStruct.parentIDX idx
if rootChildrenIDX > 0 then
(
Append str_xmlStruct.parentIDX rootChildrenIDX
)
--get attribs
get_Attribs \
child \
xml_arr
Append xml_arr str_xmlStruct
rootChildrenIDX += 1 --the index of the children directly under the Root
recurse \
child \
xml_arr
)
depth -= 1
)
)
return xml_arr;
)
)
/*
--///////////////////////////// Read XML ////////////////////////////////
str_read_xml = read_xml()
str_read_xml.report = true
--read template
-- str_read_xml.main \
-- xml_template \
-- str_read_xml._xml_template
--read definition
arr = str_read_xml.main \
xml_definition \
str_read_xml._xml
--////////////////////////////////////////////////////////////////////////
print arr
REPORT
for i=1 to str_read_xml._xml.count do
(
str_read_xml.format_tabs str_read_xml._xml[i].depth
print str_read_xml._xml[i]
)
--*/