-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththinBasic_MSXML2_DOMDocument_Node.Inc
More file actions
462 lines (416 loc) · 18.3 KB
/
thinBasic_MSXML2_DOMDocument_Node.Inc
File metadata and controls
462 lines (416 loc) · 18.3 KB
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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
' $DOMDOC_LoadXML = "LOADXML"
' $DOMDOC_Load = "LOAD"
$DOMDOCNODE_TEXT = "TEXT"
' $DOMDOC_XML = "XML"
' $DOMDOC_COUNT = "COUNT"
' $DOMDOC_SetProperty = "SETPROPERTY"
' $DOMDOC_GetProperty = "GETPROPERTY"
'
' $DOMDOC_ParseError = "PARSEERROR"
' $DOMDOC_ParseError_ErrorCode = "ERRORCODE"
' $DOMDOC_ParseError_Reason = "REASON"
' $DOMDOC_ParseError_SrcText = "SRCTEXT"
' $DOMDOC_ParseError_Line = "LINE"
' $DOMDOC_ParseError_LinePos = "LINEPOS"
' $DOMDOC_ParseError_FilePos = "FILEPOS"
' $DOMDOC_ParseError_Url = "URL"
'
' $DOMDOC_GetElementsByTagName = "GETELEMENTSBYTAGNAME"
' $DOMDOC_SelectSingleNode = "SELECTSINGLENODE"
'----------------------------------------------------------------------------------------------------------
'----------------------------------------------------------------------------
' Class
'----------------------------------------------------------------------------
Class cMsxml2_DOMNode
'----------------------------------------------------------------------------
'---Class Private variables
'----------------------------------------------------------------------------
Instance oDOMNode As IXMLDOMNode
'----------------------------------------------------------------------------
'---Define here any Class Method (if needed)
'---Class methods are visible only from inside the class
'---so they can be called only from inside other methods.
'----------------------------------------------------------------------------
Class Method Create()
'Set oDOMNode = newcom $IID_MSXML2_IXMLDOMNode'$PROGID_MSXML2_DOMDocument600
'If Not IsObject(oDOMNode) Then
' thinBasic_RunTimeError(%ERR__MODULE_SPECIFIC, "It was not possible to create a DOMDocument_Node object (" & $PROGID_MSXML2_DOMDocument600 & ")")
'End If
End Method
Class Method Destroy()
oDOMNode = Nothing
End Method
'----------------------------------------------------------------------------
' We need to define an interface that will contain public methods
'----------------------------------------------------------------------------
Interface iMsxml2_DOMNode
Inherit IUnknown
'----------------------------------------------------------------------------
' GetClassObject
'----------------------------------------------------------------------------
Method Msxml2_DOMNode_GetClassObject() As Dword
MsgBox FuncName$
Method = VarPtr(oDOMNode)
End Method
'----------------------------------------------------------------------------
' Creator Direct
'----------------------------------------------------------------------------
Method Msxml2_DOMNode_Create_Direct(ByVal ptrToDirectRecordSet As Dword) As Dword
MsgBox FuncName$ & Str$(ptrToDirectRecordSet)
'---Here is the magic: we store at the memory address of DOMNode (that is a IXMLDOMNode COM pointer)
'---The address passed by the script. The address is usually returned by another Class method or property
'---Instructed to return an OBJPTR to an ADORecordset
Poke Dword, VarPtr(oDOMNode), ptrToDirectRecordSet
End Method
Method Text() As String
Method = oDOMNode.Text
End Method
End Interface
End Class
'--------------------------------------------------------------------------------------
' We need to create a constructor wrapper function
' Constructor function will be executed by thinBasic when the class will be instantiated
' in script using the NEW keyword
'--------------------------------------------------------------------------------------
' IMPORTANT:
' ALL wrapper functions MUST HAVE a "BYVAL pObject AS LONG" parameter.
' pObject will contain a pointer to the object of our class
' This pointer is initialized by thinBasic engine to hold object reference
'--------------------------------------------------------------------------------------
Sub Msxml2_DOMNode_Create( ByVal pObject As Long )
Local pp As Byte
MsgBox FuncName$
pp = thinBasic_CheckOpenParens_Optional
If pp Then thinBasic_CheckCloseParens_Mandatory
If thinBasic_ErrorFree Then
'Here is the magic !!!!!!!!!!!!
'Use the magic REDIM ... AT and the trick is done
'We are defining a new class interface variable at the pointer location allocated by thinBasic and passed to all methods
ReDim oObject(1& To 1&) As iMsxml2_DOMNode At pObject
oObject(1&) = Class "cMsxml2_DOMNode"
End If
End Sub
'----------------------------------------------------------------------------
Sub Msxml2_DOMNode_Create_Direct(ByVal pObject As Dword, ByVal pDirectClass As Dword)
'----------------------------------------------------------------------------
Local pp As Byte
'---If all went fine ...
If thinBasic_ErrorFree Then
'Here is the magic !!!!!!!!!!!!
'Use the magic REDIM ... AT and the trick is done
'We are defining a new class interface variable at the pointer location allocated by thinBasic and passed to all methods
ReDim oObject(1& To 1&) As iMsxml2_DOMNode At pObject
'---We instantiate a new class
oObject(1&) = Class "cMsxml2_DOMDocument_Node"
'---We call sSet in order to assign initial value
oObject(1&).Msxml2_DOMNode_Create_Direct(pDirectClass)
'else
'---emit some error
End If
End Sub
'--------------------------------------------------------------------------------------
Sub Msxml2_DOMNode_Destroy( ByVal pObject As Long )
'--------------------------------------------------------------------------------------
If pObject Then
ReDim oObject(1& To 1&) As iMsxml2_DOMNode At pObject
Set oObject(1&) = Nothing
End If
End Sub
'----------------------------------------------------------------------------
Function Msxml2_DOMNode_GetClassObject(ByVal pObject As Long) As Dword
'----------------------------------------------------------------------------
If thinBasic_ErrorFree Then
ReDim oObject(1& To 1&) As iMsxml2_DOMNode At pObject
Function = oObject(1&).Msxml2_DOMNode_GetClassObject()
End If
End Function
'----------------------------------------------------------------------------
'----------------------------------------------------------------------------
'--------------------------------------------------------------------------------------
Function Msxml2_DOMNode_ClassHandling ( _
ByVal pObject As Long , _
ByVal lAction As Long , _
ByVal sPreviousName As String , _
Optional ByVal RetValNum As Ext Ptr , _
ByVal RetValStr As String Ptr , _
ByVal lRecursive As Long , _
ByVal sParam1 As String , _
ByVal sParam2 As String , _
ByVal eParam1 As Ext , _
ByVal eParam2 As Ext _
) As Long
'--------------------------------------------------------------------------------------
' IMPORTANT: function must return main return type of called method/property
'--------------------------------------------------------------------------------------
Local pp As Long
Local sName As String
Local sName2 As String
Local sName3 As String
Local sXml As String
Local sTagName As String
Local vResult As Variant
'Local pNodeList As IXMLDOMNodeList
Local Counter As Long
Local sBuffer As String
Local lIdx As Long
Local sPropName As String
Local sPropValue As String
'---As usual we map our instance (whatever it will be) to a pObject pointer
'ReDim oObject(1& To 1&) As iMsxml2_DOMDocument At pObject
ReDim oObject(1& To 1&) As iMsxml2_DOMNode At pObject
MsgBox "OK1"
ReDim pDomNode(1& To 1&) As IXMLDOMNode At oObject(1&).Msxml2_DOMNode_GetClassObject
MsgBox "OK2"
'---We need to parse next token and we need to use special fucntion: thinBasic_GetUnknownToken
'---This function is special because it instruct parser (thinCore) to not check for token validity
'---but just parse something and return whetever it will find in terms of token string
' ATTENTION: thinBasic_GetUnknownToken always return UCASE tokens in order to simplify SELECT/CASE
sName = thinBasic_GetUnknownToken
MsgBox "sName:" & sName
'---Now we have to check parsed token using token content
Select Case Const$ sName '<<<---IMPORTANT: use CONST$ to speed up Select Case operations
'-------------------------------------------------------
'---Methods
'---------------
Case $DOMDOCNODE_TEXT
Function = %thinBasic_ReturnString
'---parse Params
pp = thinBasic_CheckOpenParens_Optional
If pp Then thinBasic_CheckCloseParens_Mandatory
'---If all went fine ...
If thinBasic_ErrorFree Then
MsgBox "OK3"
If IsObject(pDomNode(1&)) Then
If lRecursive Then
'@RetValNum = Left$(@RetValStr, nChars)
Else
MsgBox "OK4"
'@RetValStr = pDomNode(1&).NodeName'Text
@RetValStr = oObject(1&).Text
MsgBox "OK5"
End If
End If
End If
MsgBox "OK9"
' Case $DOMDOC_Load
' '---We need to tell thinCore what type of info we are returning assigning to return function value the type
' '---Than assign to @RetValNum or @RetValStr the return value
' Function = %thinBasic_ReturnNumber
' '---parse Params
' pp = thinBasic_CheckOpenParens_Optional
' thinBasic_ParseString sXML
' If pp Then thinBasic_CheckCloseParens_Mandatory
' '---If all went fine ...
' If thinBasic_ErrorFree Then
' If lRecursive Then
' '@RetValNum = Left$(@RetValStr, nChars)
' Else
' @RetValNum = pDomDocument(1&).Load(sXml)
' End If
' End If
'
' Case $DOMDOC_TEXT
' Function = %thinBasic_ReturnString
' @RetValStr = pDomDocument(1&).Text
'
' Case $DOMDOC_XML
' Function = %thinBasic_ReturnString
' @RetValStr = pDomDocument(1&).XML
'
' Case $DOMDOC_ParseError
' '---Do net iteration
'
' Case $DOMDOC_ParseError_ErrorCode
' Select Case Const$ sPreviousName
' Case $DOMDOC_ParseError
' Function = %thinBasic_ReturnNumber
' @RetValNum = pDomDocument(1&).ParseError.errorCode
' End Select
' Case $DOMDOC_ParseError_Reason
' Select Case Const$ sPreviousName
' Case $DOMDOC_ParseError
' Function = %thinBasic_ReturnString
' @RetValStr = pDomDocument(1&).ParseError.Reason
' End Select
' Case $DOMDOC_ParseError_SrcText
' Select Case Const$ sPreviousName
' Case $DOMDOC_ParseError
' Function = %thinBasic_ReturnString
' @RetValStr = pDomDocument(1&).ParseError.srcText
' End Select
' Case $DOMDOC_ParseError_Line
' Select Case Const$ sPreviousName
' Case $DOMDOC_ParseError
' Function = %thinBasic_ReturnNumber
' @RetValNum = pDomDocument(1&).ParseError.Line
' End Select
' Case $DOMDOC_ParseError_LinePos
' Select Case Const$ sPreviousName
' Case $DOMDOC_ParseError
' Function = %thinBasic_ReturnNumber
' @RetValNum = pDomDocument(1&).ParseError.LinePos
' End Select
' Case $DOMDOC_ParseError_FilePos
' Select Case Const$ sPreviousName
' Case $DOMDOC_ParseError
' Function = %thinBasic_ReturnNumber
' @RetValNum = pDomDocument(1&).ParseError.FilePos
' End Select
' Case $DOMDOC_ParseError_Url
' Select Case Const$ sPreviousName
' Case $DOMDOC_ParseError
' Function = %thinBasic_ReturnString
' @RetValStr = pDomDocument(1&).ParseError.Url
' End Select
'
' Case $DOMDOC_SetProperty
' Function = %thinBasic_ReturnNumber
' pp = thinBasic_CheckOpenParens_Optional
' thinBasic_ParseString sPropName
' If thinBasic_CheckComma_Mandatory Then
' thinBasic_ParseString sPropValue
' End If
' If pp Then thinBasic_CheckCloseParens_Mandatory
'
' If thinBasic_ErrorFree Then
' If lRecursive Then
' Else
' pDomDocument(1&).SetProperty(sPropName, sPropValue)
' End If
' End If
' Case $DOMDOC_GetProperty
' Function = %thinBasic_ReturnString
' pp = thinBasic_CheckOpenParens_Optional
' thinBasic_ParseString sPropName
' If pp Then thinBasic_CheckCloseParens_Mandatory
'
' If thinBasic_ErrorFree Then
' If lRecursive Then
' Else
' sBuffer = Variant$$(pDomDocument(1&).GetProperty(sPropName))
' End If
' @RetValStr = sBuffer
' End If
'
'' Case "LEN"
'' Function = %thinBasic_ReturnNumber
'' @RetValNum = Len(@RetValStr)
'
' Case $DOMDOC_GetElementsByTagName
' '---We need to tell thinCore what type of info we are returning assigning to return function value the type
' '---Than assign to @RetValNum or @RetValStr the return value
' pp = thinBasic_CheckOpenParens_Optional
' thinBasic_ParseString sTagName
' If pp Then thinBasic_CheckCloseParens_Mandatory
'
' If thinBasic_CheckOpenParens_Optional Then
' thinBasic_ParseLong lIdx
' thinBasic_CheckCloseParens_Mandatory
' End If
'
' If thinBasic_CheckPoint_Optional Then
' sName2 = thinBasic_GetUnknownToken
' End If
'
' '---If all went fine ...
' If thinBasic_ErrorFree Then
' If lRecursive Then
' '@RetValStr = Mid$(@RetValStr, eStart, eLen)
' Else
''MsgBox "OK"
' '@RetValNum = pDomDocument(1&).GetElementsByTagName(sTagName).Length
''MsgBox "OK1:"
'
' pNodeList = pDomDocument(1&).GetElementsByTagName(sTagName)
' 'For Counter = 0 To pNodeList.length - 1
' ' sBuffer += pNodeList.Item(Counter).nodeName + ":" & pNodeList.Item(Counter).Text & $CrLf
' 'Next
''MsgBox "OK2:"
' If IsObject(pNodeList) Then
' If pNodeList.Length > 0 Then
''MsgBox "OK3:"
' lIdx = lIdx - 1
' If lIdx <= 0 Or lIdx > pNodeList.Length + 1 Then lIdx = 0
'
' Select Case Const$ sName2
' Case $DOMDOC_XML
' Function = %thinBasic_ReturnString
' sBuffer = pNodeList.Item(lIdx).xml
' @RetValStr = sBuffer
' Case $DOMDOC_TEXT
' Function = %thinBasic_ReturnString
' sBuffer = pNodeList.Item(lIdx).Text
' @RetValStr = sBuffer
' Case $DOMDOC_COUNT
' Function = %thinBasic_ReturnNumber
' @RetValNum = pNodeList.Length
' Case Else
' sBuffer = pNodeList.Item(lIdx).xml
' End Select
' End If
''MsgBox "OK4:"
' End If
' End If
' End If
'
' Case $DOMDOC_SelectSingleNode
' '---We need to tell thinCore what type of info we are returning assigning to return function value the type
' '---Than assign to @RetValNum or @RetValStr the return value
' Function = %thinBasic_ReturnString
' pp = thinBasic_CheckOpenParens_Optional
' thinBasic_ParseString sTagName
' If pp Then thinBasic_CheckCloseParens_Mandatory
'
' If thinBasic_CheckPoint_Optional Then
' sName2 = thinBasic_GetUnknownToken
' End If
'
' '---If all went fine ...
' If thinBasic_ErrorFree Then
' If lRecursive Then
' '@RetValStr = Mid$(@RetValStr, eStart, eLen)
' Else
''MsgBox "OK1:" & sTagName
' '@RetValNum = pDomDocument(1&).GetElementsByTagName(sTagName).Length
'
' Local pNode As IXMLDOMNode
' pNode = pDomDocument(1&).SelectSingleNode(sTagName)
' 'For Counter = 0 To pNodeList.length - 1
' ' sBuffer += pNodeList.Item(Counter).nodeName + ":" & pNodeList.Item(Counter).Text & $CrLf
' 'Next
' If IsObject(pNode) Then
''MsgBox "OK2"
' Select Case Const$ sName2
' Case $DOMDOC_XML
' sBuffer = pNode.xml
' Case $DOMDOC_TEXT
' sBuffer = pNode.Text
' Case Else
' sBuffer = pNode.xml
' End Select
' End If
' @RetValStr = sBuffer
' End If
' End If
'
'
Case Else
thinBasic_RunTimeError(%ERR__CLASS_METHODPROPERTY_NOTFOUND)
End Select
'-------------------------------------------------------
'---Compound methods
'---------------
' In case we have compound methods (defined as point after a method or property
' call this function recursively.
'---------------
If thinBasic_CheckPoint_Optional Then
Function = Msxml2_DOMNode_ClassHandling ( _
pObject , _
lAction , _
sName , _
RetValNum , _
RetValStr , _
%TRUE _
)
End If
End Function