forked from chandran-jr/Reubus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXML.au3
3102 lines (2739 loc) · 152 KB
/
XML.au3
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
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include-once
;~ #include <XMLConstants.au3>
#include <FileConstants.au3>
#include <StringConstants.au3>
#include <AutoItConstants.au3>
#include "ADO_CONSTANTS.au3"
#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#Tidy_Parameters=/sort_funcs /reel
#Region XML.au3 - UDF Header
; #INDEX# =======================================================================================================================
; Title .........: XML.au3
; AutoIt Version : 3.3.10.2++
; Language ......: English
; Description ...: Functions to use for reading and writing XML using msxml. (UDF based on XMLWrapper.au3)
; Remarks .......: BETA Version
; Author(s) .....: mLipok, Eltorro, Weaponx, drlava, Lukasz Suleja, oblique, Mike Rerick, Tom Hohmann, guinness, GMK
; Version .......: "1.1.1.13" ; _XML_MiscProperty_UDFVersion()
#CS
This UDF is created on the basis of:
https://www.autoitscript.com/forum/topic/19848-xml-dom-wrapper-com/
For this reason, I attach also the last known (to me) previous version ($_XMLUDFVER = "1.0.3.98" _XMLDomWrapper_1.0.3.98_CN.au3 )
For the same reason I continue to recognize the achievements of the work of my predecessors (they are still noted in each Function header).
.
.
.
. !!!!!!!!! This is BETA VERSION (all could be changed) !!!!!!!!!
.
.
.
WORK IN PROGRESS INFORMATION:
. For now 2015-09-01 the descripion (Function Header) can not entirely correctly describe the function.
. TODO: in many places I used "TODO" as a keyword to find what should be done in future
. TO REMOVE _XML_NodeExists(ByRef $oXmlDoc, $sXPath)as is duplicate for _XML_SelectSingleNode($oXmlDoc, $sXPath)
.
I want to: PREVENT THIS:
. The unfortunate nature of both the scripts is that the func return results are strings or arrays instead of objects.
.
I want to: USE THIS CONCEPT:
. All function should use Refernce to the object as first Function parameter
. All function should return in most cases objects. There should be separate functions to Change Object collection to array
. All function should use COM Error Handler in local scope.
. All function should return @error which are defined in Region XMLWrapperEx.au3 - ERROR Enums
. All function should have the same naming convention
. All variables should have the same naming convention
. There should not to be any Global Variable - exception is $__g_oXMLDOM_EventsHandler
. It should be possible easy to use XML DOM Events
. https://msdn.microsoft.com/en-us/library/ms764697(v=vs.85).aspx
. It should be possible easy to Debug
. Ultimately, you should be able to do anything with your XML without having to use your own Error Handler.
. MAIN MOTTO: "Programs are meant to be read by humans, and only incidentally for computers to execute." - Donald Knuth
#CE
#CS
; !!!!!!!!!!!!!!!! the previous version of UDF
; Author ........: Stephen Podhajecki - Eltorro <gehossafats@netmdc.com>
; Author ........: Weaponx
; Modified ......: drlava, Lukasz Suleja, oblique, Mike Rerick, Tom Hohmann
; Initial release Dec. 15, 2005
;; There is also _MSXML.au3 at http://code.google.com/p/my-autoit/source/browse/#svn/trunk/Scripts/MSXML
;; http://my-autoit.googlecode.com/files/_MSXML.au3
;; which return the xml object instead of using a global var.
;;
;; Therefore using the one above, more than one xml file can be opened at a time.
;; The unfortunate nature of both the scripts is that the func return results are strings or arrays instead of objects.
!!!!!!!!!!!! The following description is intended only to show the extent of the changes that have taken place in relation to the source version of the UDF
!!!!!!!!!!!! PLEASE TREAT THIS AS QUITE NEW UDF
2015/09/02
"1.1.1.01"
. Global Variable renaming: $fXMLAUTOSAVE > $g__bXMLAUTOSAVE - mLipok
. Global Variable renaming: $fADDFORMATTING > $g__bADDFORMATTING - mLipok
. Global Variable renaming: $DOMVERSION > $g__iDOMVERSION - mLipok
. Global Variable renaming: $_XMLUDFVER > $g__sXML_UDF_VERSION - mLipok
. Local Variable renaming: $fDebug > $bDebug - mLipok
. Local Variable renaming: $strNameSpc > $sNameSpace - mLipok
. Local Variable renaming: $strXPath > $sXPath - mLipok
. added EventHandler for __XML_DOM_EVENT_onreadystatechange - mLipok
. added EventHandler for __XML_DOM_EVENT_ondataavailable - mLipok
. added EventHandler for __XML_DOM_EVENT_ontransformnode - mLipok
. _XML_Misc* functions renamed and extended - mLipok
. #Region -- grouping functions - mLipok
. New Enums - Stream Object - ReadText Method - StreamReadEnum - mLipok
. New Enums - readyState Property (DOMDocument) - mLipok
. New Function: __XML_ComErrorHandler_UserFunction - mLipok
. added ADO_CONSTANTS.au3 - mLipok
??
. __XML_ComErrorHandler_InternalFunction() CleanUp - mLipok
. __XML_ComErrorHandler_InternalFunction() new parameters - mLipok
SCRIPT BREAKING CHANGES
. all function renamed from _XMLSomeName to _XML_SomeName ; TODO not yet all, but that is the plan - mLipok
. Function _DebugWrite renamed to __XML_Misc_ConsoleNotifier - mLipok
. Function _XSL_GetDefaultStyleSheet renamed to __XSL_GetDefaultStyleSheet - mLipok
. Function _XMLGetDomVersion renamed to _XML_Misc_GetDomVersion - mLipok
. Func _SetDebug renamed to _XML_MiscProperty_NotifyToConsole - mLipok
. Removed $fDEBUGGING as is now used inside _XML_MiscProperty_NotifyToConsole - mLipok
. Removed $bXMLAUTOSAVE as is now used inside _XML_MiscProperty_AutoSave - mLipok
. Removed $bADDFORMATTING as is now used inside _XML_MiscProperty_AutoFormat - mLipok
. Removed $g__iDOMVERSION as is now used inside __XML_MiscProperty_DomVersion - mLipok
. standardarization for using Return Value for failure: return 0 and set @error to none 0 - mLipok
. _XML_Load on success return $oXmlDoc instead 1 - mLipok
. _XML_LoadXML on success return $oXmlDoc instead 1 - mLipok
. $oXmlDoc is no longer global variable (must be passed to function as ByRef) - mLipok
. removed many variable declaration used even for variable iteration "For $i to 10" - mLipok
2015/09/04
"1.1.1.02"
. event handler renamed to $__g_oXMLDOM_EventsHandler - mLipok
. added $XMLWRAPPER_ERROR_SAVEFILERO and checking in - mLipok
. if variable is ObjectsCollection then variable name ends with sufix "Coll" - mLipok
. variable used in loops are named with sufix "_idx" like this For $iAttribute_idx = 0 To $oAttributes_coll.length - 1 - mLipok
. variable used in loops are named with sufix "Enum" like this For $oNode_enum in $oNodes_coll - mLipok
. Local Variable renaming: $strQuery > $sQuery - mLipok - thanks to guinness
. Local Variable renaming: $sComment > $sComment - mLipok - thanks to guinness
. Function renamed fixed typo in function name _XML_CreateAttributeute => _XML_CreateAttribute - mLipok - thanks to guinness
. Function renamed _XML_Misc_NodesList_GetNames >> _XML_Array_GetNodesNamesFromCollection - mLipok
. Global Enum renamed from $g__eXML_ ..... to $__g_eXML_ ..... - mLipok
. Function renamed _XML_ArrayAdd >> _XML_Array_AddName - mLipok
. Function renamed _XML_Misc_NodesColl_GetNamesToArray >> _XML_Array_GetNodesNamesFromCollection - mLipok
. Function renamed _XML_DeleteNode_XML_DeleteNode >> _XML_removeAll - mLipok
. Function renamed _XML_FileOpen >> _XML_Load - mLipok
. new Function _XML_Array_GetNodeList() - mLipok
. UDF FileName: _XMLWrapperEx.au3 >> XMLWrapperEx.au3 - mLipok
. !!! EXAMPLES FILE: XMLWrapperEx__Examples.au3 - mLipok
2015/09/06
"1.1.1.03"
. Renamed Function: _XMLCreateChildWAttr >> _XML_CreateChildWAttr - mLipok
. Renamed ENUMs: $__g_eXML_ERROR ... >> $XMLWRAPPER_ERROR ... - mLipok - Thanks to guinness
. Renamed ENUMs: $__g_eXML_RESULT ... >> $XMLWRAPPER_RESULT ... - mLipok - Thanks to guinness
. Renamed CONST: $XMLDOM_DOCUMENT_READYSTATE_ ... >> $XMLWRAPPER_DOCUMENT_READYSTATE_ ... - mLipok - Thanks to guinness
. Renamed Variable : $oXML_Document >> $oXmlDoc - for shortness, and compliance with examples of MSDN - mLipok
. New Example: _Example_2__XML_CreateChildWAttr - mLipok
. New Example: _Example_3__XML_Misc_ErrorDecription - mLipok
. New Example: _Example_MSDN_1__setAttributeNode - mLipok
. New Function: _XML_Misc_Viewer - mLipok
. New: Function: _XML_Misc_ErrorParser() -- added as a replacment for using: _XML_Misc_ErrorDecription() - mLipok
. NEW: @ERROR result: $XMLWRAPPER_ERROR_ARRAY - mLipok
. NEW: @ERROR result: $XMLWRAPPER_ERROR_NODECREATEAPPEND - mLipok
. Removed: all old _XML_Misc_ErrorDecription() - mLipok
. Removed: _XML_Misc_ErrorDecription_Reset()- mLipok
. Removed: all $sXML_error - mLipok
. Removed: _XML_Error_Reason - mLipok
. COMPLETED: @error checking for .selectNodes methods: @error is set to: $XMLWRAPPER_ERROR_XPATH - mLipok
. COMPLETED: _XML_CreateChildWAttr - mLipok
. COMPLETED: Standardarization for using Return Value @error codes returned from function --> ENUMERATED CONSTATNS - mLipok
. Now all functions Return like the following examples:
. Return SetError($XMLWRAPPER_ERROR_ .........
. or in this way:
. If @error Then Return SetError(@error, @extended, $XMLWRAPPER_RESULT_FAILURE)
2015/09/07
"1.1.1.04"
. Renamed: $iXMLWrapper_Error_number >> $iXMLWrapper_Error - mLipok
. Removed: almost all MsgBox() - leaves only in __XML_Misc_MsgBoxNotifier() - mLipok
. Changed: in Examples : Global $oErrorHandler >> Local $oErrorHandler - mLipok
. Renamed _XML_Array_GetNodeList >> _XML_Array_GetNodesProperties - mLipok
. Removed: _XML_Array_GetNodesFromCollection as this was duplicate for _XML_Array_GetNodesProperties - mLipok
. NEW: $__g_eARRAY_NODE_ATTRIBUTES in function _XML_Array_GetNodesProperties - now also display all atributes - mLipok
. Renamed: _XML_MiscProperty_DomVersion >> __XML_MiscProperty_DomVersion - as this should be internal - as you can use _XML_Misc_GetDomVersion() - mLipok
. Renamed: _XML_ComErrorHandler_MainFunction >> __XML_ComErrorHandler_UserFunction - as this should be internal - mLipok
. Renamed: _XML_ErrorParser >> _XML_ErrorParser_GetDescription - mLipok
. Removed: _XML_Misc_ErrorParser - will be in Examples - mLipok
. Changed: Return value behavior - mLipok
. From:
. SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $oXmlDoc.parseError.reason)
. SetError($XMLWRAPPER_ERROR_PARSE, $oXmlDoc.parseError.errorCode, $XMLWRAPPER_RESULT_FAILURE)
. Changed: _XML_Load and _XML_LoadXML require $oXmlDoc as first parameter, you must use _XML_CreateDOMDocument() as only in this way it is possible to use _XML_ErrorParser_GetDescription() - mLipok
. All examples changed to show how to use "new" _XML_Load and _XML_LoadXML
. NEW: ENUMs: $XMLWRAPPER_ERROR_EMPTYCOLLECTION - mLipok
. NEW: ENUMs: $XMLWRAPPER_ERROR_NONODESMATCH - mLipok
. Changed: MAGIC NUMBERS: for StringStripWS in _XML_DeleteNode() - mLipok
. COMPLETED: _XML_NodeExists - mLipok
. COMPLETED: Refactroing all functions with "selectNodes" Method now have checking: If (Not IsObj($oNodes_coll)) Or $oNodes_coll.length = 0 Then ... SetError($XMLWRAPPER_ERROR_EMPTYCOLLECTION ..... - mLipok
. COMPLETED: Refactroing all functions with "selectSingleNode" Method now have checking: If $oNode_Selected = Null Then .. SetError($XMLWRAPPER_ERROR_NONODESMATCH ..... - mLipok
2015/09/09
"1.1.1.05"
. NEW: ENUMs: $XMLWRAPPER_ERROR_PARSE_XSL - mLipok
. NEW: ENUMs: $XMLWRAPPER_ERROR_NOATTRMATCH - mLipok
. COMPLETED: Function: _XML_RemoveAttribute() - mLipok
. NEW EXAMPLE: _Example_4__XML_RemoveAttribute() - mLipok
. Renamed: _XMLReplaceChild >> _XML_ReplaceChild - mLipok
. COMPLETED: _XML_ReplaceChild - mLipok
. NEW EXAMPLE: _Example_5__XML_ReplaceChild() - mLipok
. NEW: ENUMs: $XMLWRAPPER_ERROR_NOCHILDMATCH - mLipok
. NEW EXAMPLE: _Example_6__XML_GetChildNodes() - mLipok
. COMPLETED: _XML_GetChildNodes() - mLipok
. COMPLETED: _XML_GetAllAttribIndex() - mLipok
. NEW Function: _XML_Array_GetAttributesProperties() - mLipok
. NEW EXAMPLE: _Example_7__XML_GetAllAttribIndex() - mLipok
. ADDED: many IsObj() >> https://www.autoitscript.com/forum/topic/177176-why-isobj-0-and-vargettype-object/
2015/09/11
"1.1.1.06"
. Removed: Function: __XML_Misc_ConsoleNotifier() - mLipok
. Removed: Function: __XML_Misc_MsgBoxNotifier() - mLipok
. Removed: Function: _XML_MiscProperty_Notify() - mLipok
. Removed: Function: _XML_MiscProperty_NotifyToConsole() - mLipok
. Removed: Function: _XML_MiscProperty_NotifyToMsgBox() - mLipok
. Removed: Function: _XML_MiscProperty_NotifyAll() - mLipok
. Removed: Function: __XML_ComErrorHandler_MainFunction() - mLipok
. Removed: Function: __XML_DOM_EVENT_ondataavailable() >> is in example - mLipok
. Removed: Function: __XML_DOM_EVENT_onreadystatechange() >> is in example - mLipok
. Removed: Function: __XML_DOM_EVENT_ontransformnode() >> is in example - mLipok
. Removed: Function: _XML_UseEventHandler() - as event handler should be defined by user in main script - look in examlpes - mLipok
. Removed: Function: _XML_ComErrorHandler_UseInternalAsUser() - mLipok
. Renamed: Function: _XML_ComErrorHandler_UserFunction >> __XML_ComErrorHandler_UserFunction - is now internal - mLipok
. User Function are now passed as parameter to _XML_CreateDOMDocument()
. Changed: Examples: XML_Misc_ErrorParser() >> XML_My_ErrorParser() - mLipok
. Changed: Examples to fit to the changed UDF - mLipok
. Modified: Examples: CleanUp +++ Comments - mLipok
. Removed: Function: __AddFormat - as now is _XML_TIDY() function - mLipok
. Removed: Function: _XML_MiscProperty_StaticCOMErrorHandler() - as was not used - mLipok
.
.
. !!!!!! REMARKS: - mLipok
. It is user choice to set ERROR HANDLER or not.
. If user do not set it and something goes wrong with COM then this is USER PROBLEM and NOT UDF ISSUE/ERROR
. in such case UDF will call empty function for avoid AutoIt Error
. FOR ERROR CHECKING
. 1. check @error
. 2. _XML_ErrorParser_GetDescription()
. 3. setup your COM ERROR HANDLER and pass it as parameter to _XML_CreateDOMDocument()
. 4. you can make in your main script function like XML_My_ErrorParser() and use it if you want
2015/09/15
"1.1.1.07"
. Renamed: ENUMs: $eAttributeList_ ..... >> $__g_eARRAY_ATTR_ .... - as now are Global Enums - mLipok
. Renamed: ENUMs: $eNodeList_ ..... >> $__g_eARRAY_NODE_ .... - as now are Global Enums - mLipok
. Removed: Function: _XML_MiscProperty_AutoFormat() - as is not used - mLipok
. Removed: Function: _XML_MiscProperty_EventHandling() - as is not used - mLipok
. Removed: Function: _XML_MiscProperty_AutoSave() - as is not used - mLipok
. ADDED NEW: Function: __XML_IsValidObject_Attributes() - mLipok
. ADDED NEW: Function: __XML_IsValidObject_NodesColl() - mLipok
. ADDED NEW: $XMLWRAPPER_EXT_ ... for proper handling @extended information - mLipok
. Changed: Examples: XML_My_ErrorParser() - added support for $XMLWRAPPER_EXT_ ... - mLipok
. Removed: $sQuery - DOM compliant query string (not really necessary as it becomes part of the path) - mLipok
. Changed: All @extended are returned as $XMLWRAPPER_EXT_ .... or @extended - never as 0 or directly as number - mLipok
. REFACTORED: _XML_Tidy() - proper @errors and @extended support - mLipok
. REFACTORED: _XML_Array_GetAttributesProperties() - proper @errors and @extended support - mLipok
. REFACTORED: _XML_Array_GetNodesProperties() - proper @errors and @extended support - mLipok
. REFACTORED: all this following function uses _XML_SelectNodes() - mLipok
. _XMLCreateChildNode() _XML_DeleteNode() _XML_GetAllAttribIndex()
. _XML_GetParentNodeName() _XMLSetAttrib() _XML_UpdateField2()
. _XMLGetValue() _XML_GetNodesCount() _XML_ReplaceChild()
. _XML_GetNodesPath() _XMLGetAllAttrib()
. REFACTORED: all this following function uses _XML_SelectSingleNode() - mLipok
. _XML_CreateAttribute() _XML_CreateComment() _XML_GetAttrib()
. _XML_GetChildNodes() _XML_GetChildren() _XML_NodeExist()
. _XML_RemoveAttribute() _XML_GetChildText() _XML_UpdateField()
. _XMLGetField()
. Renamed: Function: __XML_IsValidObject >> __XML_IsValidObject_DOMDocument - mLipok
. COMPLETED: Function: _XML_SaveToFile - mLipok
. Removed: $XMLWRAPPER_ERROR_NODECREATEAPPEND - mLipok
. ADDED: $XMLWRAPPER_ERROR_NODECREATE - mLipok
. ADDED: $XMLWRAPPER_ERROR_NODEAPPEND - mLipok
. Changed: Functions to proper use $XMLWRAPPER_ERROR_NODECREATE and $XMLWRAPPER_ERROR_NODEAPPEND - mLipok
. Renamed: Function: __XML_IsValidObject_Nodes >> __XML_IsValidObject_NodesColl - mLipok
. Renamed: ENUMs: $XMLWRAPPER_EXT_OK >> $XMLWRAPPER_EXT_DEFAULT - mLipok
. Renamed: Function: _XML_GetNodeCount >> _XML_GetNodesCount - mLipok
. Renamed: Function: _XML_GetAttrib >> _XML_GetNodeAttributeValue - mLipok
. Changed: Function: _XML_GetNodeAttributeValue - parameters chagned - must pass $oNode instead $oXmlDoc - mLipok
. COMPLETED: Function: _XML_LoadXML - mLipok
. COMPLETED: Function: _XML_CreateDOMDocument - mLipok
. COMPLETED: Function: _XML_Tidy - mLipok
. Renamed: Function: _XML_CreateObject >> _XML_CreateDOMDocument - mLipok
. NEW: Region: XMLWrapperEx.au3 - Functions - Not yet reviewed - mLipok
. NEW: Region: XMLWrapperEx.au3 - Functions - COMPLETED - mLipok
. COMPLETED: Function: _XML_GetNodeAttributeValue - mLipok
. other CleanUp - mLipok
2015/10/22
"1.1.1.08"
. ADDED: Description for _XML_ErrorParser_GetDescription() - mLipok
. ADDED: Description for _XML_Array_GetNodesProperties() - mLipok
. Fixed: Function: _XMLCreateFile () - mLipok
. Issue with usage of Tenary Operator in $oXmlDoc.createProcessingInstruction("xml", 'version="1.0"' & (($bUTF8) ? ' encoding="UTF-8"' : ''))
. Renamed: Function: _XMLCreateFile >> _XML_CreateFile - mLipok
. Completed: Function: _XML_CreateFile - mLipok
. !!! EXAMPLES FILE: New Example: Example_9__XML_CreateFile() - mLipok
. !!! EXAMPLES FILE: Changed to Keep the changed Script Breaking Changes - mLipok
. Renamed: Function: __XML_ComErrorHandler_UserFunction >> _XML_ComErrorHandler_UserFunction : is now normal function - not internal - mLipok
. NEW: methode of transfer UDF internal COM Error Handler to the user function - mLipok
. just use _XML_ComErrorHandler_UserFunction() like in example
.
SCRIPT BREAKING CHANGES
. Renamed: Enums: $XMLWRAPPER_RESULT_ >> $XML_RET_ - mLipok
. Renamed: Enums: $XMLWRAPPER_EXT_ >> $XML_EXT_ - mLipok
. Renamed: Enums: $XMLWRAPPER_ERROR_ >> $XML_ERR_ - mLipok
. Renamed: Enums: $NODE_ >> $XML_NODE_ - mLipok
. Removed: Parameter: _XML_CreateDOMDocument > $vComErrFunc - mLipok
2016/05/18
"1.1.1.09"
. !!!! UDF RENAMED XMLWrapperEx.au3 >> XML.au3 - mLipok
. Changed: Error Handling: all SetError($XML_ERR_NODEAPPEND, - returns @error as extended - as this is COM ERROR - mLipok
. Changed: Error Handling: all SetError($XML_ERR_NODECREATE, - returns @error as extended - as this is COM ERROR - mLipok
. Removed: Function: _XMLCreateChildNode - as it was duplicate feature with _XML_CreateChildWAttr - mLipok
. Thanks to: @scila1996
. https://www.autoitscript.com/forum/topic/176895-xmlwrapperexau3-beta/?do=findComment&comment=1278825
. Removed: Function: _XMLCreateChildNodeWAttr - as it was only duplicate/wrapper for _XML_CreateChildWAttr - mLipok
. Thanks to: @scila1996
. https://www.autoitscript.com/forum/topic/176895-xmlwrapperexau3-beta/?do=findComment&comment=1278825
. ! EXAMPLES FILE: Modified: XML_My_ErrorParser - mLipok
. ! EXAMPLES FILE: New: Example_2a__XML_CreateChildWAttr() - mLipok
. Removed: Enums: $XML_ERR_SAVEFILERO - New Requirment for saving - File Can Not Exist - user should manage it by their own - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDNODESE >> $XML_ERR_ISNOTVALIDNODETYPE - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDNODETYPE >> $XML_ERR_INVALIDNODETYPE - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDATTRIB >> $XML_ERR_INVALIDATTRIB - mLipok
. Renamed: Enums: $XML_ERR_ISNOTVALIDDOMDOC >> $XML_ERR_INVALIDDOMDOC - mLipok
. Removed: $XML_EXT_GENERAL >> $XML_EXT_DEFAULT - mLipok
. Changed: $XML_EXT_.. are reordered - mLipok
. Removed: Function: _XSL_GetDefaultStyleSheet - mLipok
. This was example from:
. http://www.xml.com/lpt/a/1681
. But it is: Copyright © 1998-2006 O'Reilly Media, Inc.
. Renamed: Function: _XMLGetField >> _XML_GetField - mLipok
. Renamed: Function: _XMLGetValue >> _XML_GetValue - mLipok
. Renamed: Function: _XMLGetAllAttrib >> _XML_GetAllAttrib - mLipok
. Renamed: Function: _XMLSetAttrib >> _XML_SetAttrib - mLipok
. New: Function: _XML_InsertChildNode - GMK
. New: Function: _XML_InsertChildWAttr - GMK
. Changed: Function: _XML_CreateAttribute - numbers of parameters - mLipok
. now you must pass an Array with AttributeName and AttributeValue
. Fixed: Function: _XMLCreateRootNode - GMK
. $oXmlDoc.documentElement.appendChild($oChild) >> $oXmlDoc.appendChild($oChild)
. Fixed: Function: _XMLCreateRootNodeWAttr - GMK
. $oXmlDoc.documentElement.appendChild($oChild_Node) >> $oXmlDoc.appendChild($oChild_Node)
. Renamed: Function: _XMLCreateRootChild >> _XML_CreateRootNode - GMK
. !!!!!!!! @TODO need to be revisited
.
. Renamed: Function: _XMLCreateRootNodeWAttr >> _XML_CreateRootNodeWAttr - GMK
. ADDED: #CURRENT# - GMK
. ADDED: #IN_PROGESS# - GMK
. ADDED: #INTERNAL_USE_ONLY# - GMK
. !!! Additional Thanks for GMK for testing and many changes in many Description
. CleanUp: Function: _XML_GetNodesPath - removed $sNodePathTag - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetParentNodeName - removed $sNodePathTag - mLipok - thanks to GMK
. CleanUp: Function: removed #include <MsgBoxConstants.au3> - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetField - removed $oChild - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetNodesPath - MagicNumber 0 replaced with $STR_NOCASESENSE - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetNodesPathInternal - MagicNumber 0 replaced with $STR_NOCASESENSE - mLipok - thanks to GMK
. CleanUp: Function: _XML_GetParentNodeName - MagicNumber 0 replaced with $STR_NOCASESENSE - mLipok - thanks to GMK
. Renamed: Function: _XMLCreateCDATA >> _XML_CreateCDATA - mLipok - thanks to GMK
. Rewrite: Function: _XML_GetAllAttrib - Parameters : removed ByRef $aName, ByRef $aValue - mLipok
. Fixed Typo: Descripton: Chceck >> Check - mLipok - thanks to GMK
. Added: Descripton: _XML_GetNodesCount - mLipok - thanks to GMK
. Changed: Descripton: _XML_TransformNode - mLipok - thanks to GMK
. Changed: Descripton: _XML_CreateDOMDocument - mLipok - thanks to GMK
. Added: Descripton: _XML_GetNodeAttributeValue - mLipok - thanks to GMK
. Changed: Descripton: _XML_Misc_Viewer - mLipok - thanks to GMK
.
. Changed: Function: _XML_SelectNodes in case of success @extended = $oNodes_coll.length
.
.
2016/05/18
"1.1.1.10"
. NEW: Feature: _XML_Tidy: if Parameter $sEncoding = -1 then .omitXMLDeclaration = true - mLipok
. Feature asked by @GMK here:
. https://www.autoitscript.com/forum/topic/176895-xmlau3-v-11109-formerly-xmlwrapperexau3-beta-support-topic/?do=findComment&comment=1294688
. Changed: _XML_Tidy(ByRef $oXmlDoc, $sEncoding = -1) - Default value is set to -1 - mLipok
. New: XML__Example_TIDY.au3 - mLipok
.
.
2016/06/16
"1.1.1.11"
. NEW: Function: __XML_IsValidObject_DOMDocumentOrElement - mLipok
. Changed: Function: _XML_SelectNodes - parameter validation __XML_IsValidObject_DOMDocumentOrElement - mLipok
. Currently _XML_SelectNodes can use relative XPath
. Changed: Function: _XML_SelectSingleNode - parameter validation __XML_IsValidObject_DOMDocumentOrElement - mLipok
. Currently _XML_SelectSingleNode can use relative XPath
. Refactored: Function: _XML_CreateComment - mLipok
. Changed: Function: @error > $XML_ERR_COMERROR - mLipok
. Fixed: Function: _XML_Array_GetNodesProperties - properly gets all attributes - mLipok
.
. EXAMPLES: New, and checked/refactored/fixed
. XML__Examples_TIDY.au3
. XML__Examples_User__asdf1nit.au3
. XML__Examples_User_coma.au3
. XML__Examples_User_Realm.au3
. XML__Examples_User_scila1996.au3
. XML__Examples_User_DarkAqua__Tasks.au3
2016/10/27
"1.1.1.12"
. Changed: Function: _XML_SetAttrib - support for $vAttributeNameOrList - GMK
. Added: Enums: $XMLATTR_COLNAME, $XMLATTR_COLVALUE, $XMLATTR_COLCOUNTER - mLipok
. Changed: Function: _XML_GetAllAttrib - !!! array result is reordered ROWS<>COLS - mLipok
. now are coherent manner for: _XML_InsertChildWAttr, _XML_CreateChildWAttr, _XML_SetAttrib, _XML_GetAllAttrib
. THIS IS !!! SCRIPT BREAKING CHANGE !!!
. Added: Function parameter: _XML_Load new parameter $bPreserveWhiteSpace = True - GMK
. Added: Function parameter: _XML_LoadXML new parameter $bPreserveWhiteSpace = True - GMK
. Changed: Enums: $XML_ERR_OK >> $XML_ERR_SUCCESS - for unification/coherence in relatation to some other UDF's - mLipok
.
. EXAMPLES: New, and checked/refactored/fixed
. XML__Examples_TIDY2.au3
. XML__Examples_User_BlaBlaFoo__Dellwarranty.au3
. XML__Examples_User_Shrapnel.au3
.
.
2017/03/05
"1.1.1.13"
. Added: Function: _XML_Base64Encode() - mLipok
. Added: Function: _XML_Base64Decode() - mLipok
. Fixed: bug in: _XML_Array_AddName() - krupa
. Changed: $ADOENUM_ad* >>> $ADO_ad** - to be coherent with ADO.au3 UDF - mLipok
.
2017/xx/xx
"1.1.1.xx"
.
.
.
.
.
.
@LAST - this keyword is usefull for quick jumping here
TODO LIST:
. TODO CHECK: _XML_GetField, _XML_GetValue
. @WIP TODO: COUNT = 50
. TODO: Description, Function Header CleanUp (are still old)
. TODO: browse entire UDF for TODO "Keyword"
. TODO: Return SetError($XML_ERR_GENERAL ... should be used only once per function
. TODO: Return SetError($XML_ERR_GENERAL ... should be always ONLY as the last Error returned from function
. TODO: $XML_ERR_ .... should be reordered it will be SCRIPT BREAKING CHANGES: only if used MAGIC NUMBERS for @error checking
. TODO: GMK: What's a better way to insert a node before a specified node object or XPath for _XML_InsertChildNode and _XML_InsertChildWAttr? Replace $iItem with $oInsertBeforeNode?
. TODO: GMK: Rename _XML_Transform ==> _XML_TransformNodeToObj (?)
. TODO: GMK: Why not combine _XML_UpdateField and _XML_UpdateField2? Would inputting parameters for a single node XPath not work the same for _XML_UpdateField2 as it would for _XML_UpdateField?
#CE
; #CURRENT# =====================================================================================================================
; _XML_CreateAttribute
; _XML_CreateComment
; _XML_DeleteNote
; _XML_GetChildren
; _XML_GetChildText
; _XML_GetNodesPath
; _XML_GetNodesPathInternal
; _XML_GetParentNodeName
; _XML_RemoveAttributeNode
; _XML_ReplaceChild
; _XML_Transform
; _XML_UpdateField
; _XML_UpdateField2
; _XML_ValidateFile
; _XML_CreateCDATA
; _XML_CreateChildNode
; _XML_CreateRootNode
; _XML_CreateRootNodeWAttr
; _XML_GetAllAttrib
; _XML_GetAllAttribIndex
; _XML_GetField
; _XML_GetValue
; _XML_SetAttrib
; _XML_CreateChildWAttr
; _XML_CreateDOMDocument
; _XML_CreateFile
; _XML_GetChildNodes
; _XML_GetNodeAttributeValue
; _XML_Load
; _XML_LoadXML
; _XML_NodeExists
; _XML_SaveToFile
; _XML_SelectNodes
; _XML_SelectSingleNode
; _XML_Tidy
; _XML_Misc_GetDomVersion
; _XML_Misc_Viewer
; _XML_MiscProperty_UDFVersion
; _XML_Array_AddName
; _XML_Array_GetAttributesProperties
; _XML_Array_GetNodesProperties
; _XML_ErrorParser_GetDescription
; #IN_PROGESS# ==================================================================================================================
; _XML_InsertChildNode
; _XML_InsertChildWAttr
; _XML_GetNodesCount
; _XML_RemoveAttribute
; _XML_TransformNode
; _XML_MiscProperty_Encoding
; #INTERNAL_USE_ONLY# ===========================================================================================================
; __XML_IsValidObject_Attributes
; __XML_IsValidObject_DOMDocument
; __XML_IsValidObject_DOMDocumentOrElement
; __XML_IsValidObject_Node
; __XML_IsValidObject_NodesColl
; __XML_MiscProperty_DomVersion
; __XML_ComErrorHandler_InternalFunction
; __XML_ComErrorHandler_UserFunction
#EndRegion XML.au3 - UDF Header
; #VARIABLES# ===================================================================================================================
#Region XML.au3 - Enumeration - ERROR EXTENDED RETURN
Global Enum _
$XML_ERR_SUCCESS, _ ; All is ok
$XML_ERR_GENERAL, _ ; The error which is not specifically defined.
$XML_ERR_COMERROR, _ ; COM Error occured - Check @extended for COMERROR Number or check you COM Error Handler Function
$XML_ERR_DOMVERSION, _ ; Check @extended for required DOM Version
$XML_ERR_ISNOTOBJECT, _ ; No object passed to function.
$XML_ERR_INVALIDDOMDOC, _ ; Invalid object passed to function - expected Document.
$XML_ERR_INVALIDATTRIB, _ ; Invalid object passed to function - expected Attrib Element.
$XML_ERR_INVALIDNODETYPE, _ ; Invalid object passed to function - expected Node Element.
$XML_ERR_OBJCREATE, _ ; Object can not be created.
$XML_ERR_NODECREATE, _ ; Can not create Node - check also extended for node type
$XML_ERR_NODEAPPEND, _ ; Can not append Node - check also extended for node type
$XML_ERR_PARSE, _ ; Error with Parsing objects use _XML_ErrorParser_GetDescription() for Get details
$XML_ERR_PARSE_XSL, _ ; Error with Parsing XSL objects use _XML_ErrorParser_GetDescription() for Get details
$XML_ERR_LOAD, _ ; Error opening specified file.
$XML_ERR_SAVE, _ ; Error saving file.
$XML_ERR_PARAMETER, _ ; Wrong parameter passed to function.
$XML_ERR_ARRAY, _ ; Wrong array parameter passed to function. Check array dimension and conent.
$XML_ERR_XPATH, _ ; XPath syntax error - you should check also COM Error Handler.
$XML_ERR_NONODESMATCH, _ ; No nodes match the XPath expression
$XML_ERR_NOCHILDMATCH, _ ; There is no Child in nodes matched by XPath expression.
$XML_ERR_NOATTRMATCH, _ ; There is no such attribute in selected node.
$XML_ERR_EMPTYCOLLECTION, _ ; Collections of objects was empty
$XML_ERR_EMPTYOBJECT, _ ; Object is empty
$XML_ERR_ENUMCOUNTER ; not used in UDF - just for other/future testing
Global Enum _
$XML_EXT_DEFAULT, _ ; Default - Do not return any additional information, The extended which is not specifically defined.
$XML_EXT_PARAM1, _ ; Error Occurs in 1-Parameter
$XML_EXT_PARAM2, _ ; Error Occurs in 2-Parameter
$XML_EXT_PARAM3, _ ; Error Occurs in 3-Parameter
$XML_EXT_PARAM4, _ ; Error Occurs in 4-Parameter
$XML_EXT_PARAM5, _ ; Error Occurs in 5-Parameter
$XML_EXT_PARAM6, _ ; Error Occurs in 6-Parameter
$XML_EXT_XMLDOM, _ ; "Microsoft.XMLDOM" related Error
$XML_EXT_DOMDOCUMENT, _ ; "Msxml2.DOMDocument" related Error
$XML_EXT_XSLTEMPLATE, _ ; "Msxml2.XSLTemplate" related Error
$XML_EXT_SAXXMLREADER, _ ; "MSXML2.SAXXMLReader" related Error
$XML_EXT_MXXMLWRITER, _ ; "MSXML2.MXXMLWriter" related Error
$XML_EXT_FREETHREADEDDOMDOCUMENT, _ ; "Msxml2.FreeThreadedDOMDocument" related Error
$XML_EXT_XMLSCHEMACACHE, _ ; "Msxml2.XMLSchemaCache." related Error
$XML_EXT_STREAM, _ ; "ADODB.STREAM" related Error
$XML_EXT_ENCODING, _ ; Encoding related Error
$XML_EXT_ENUMCOUNTER ; not used in UDF - just for other/future testing
Global Enum _
$XML_RET_FAILURE, _ ; UDF Default Failure Return Value
$XML_RET_SUCCESS, _ ; UDF Default Success Return Value
$XML_RET_ENUMCOUNTER ; not used in UDF - just for other/future testing
#EndRegion XML.au3 - Enumeration - ERROR EXTENDED RETURN
#Region XML.au3 - ARRAY Enums
; Enums for _XML_Array_GetAttributesProperties() function
Global Enum _
$__g_eARRAY_ATTR_NAME, _
$__g_eARRAY_ATTR_TYPESTRING, _
$__g_eARRAY_ATTR_VALUE, _
$__g_eARRAY_ATTR_TEXT, _
$__g_eARRAY_ATTR_DATATYPE, _
$__g_eARRAY_ATTR_XML, _
$__g_eARRAY_ATTR_ARRAYCOLCOUNT
; Enums for _XML_Array_GetNodesProperties() function
Global Enum _
$__g_eARRAY_NODE_NAME, _
$__g_eARRAY_NODE_TYPESTRING, _
$__g_eARRAY_NODE_VALUE, _
$__g_eARRAY_NODE_TEXT, _
$__g_eARRAY_NODE_DATATYPE, _
$__g_eARRAY_NODE_XML, _
$__g_eARRAY_NODE_ATTRIBUTES, _
$__g_eARRAY_NODE_ARRAYCOLCOUNT
; Enums for _XML_InsertChildWAttr, _XML_CreateChildWAttr, _XML_SetAttrib, _XML_GetAllAttrib
Global Enum _
$XMLATTR_COLNAME, _
$XMLATTR_COLVALUE, _
$XMLATTR_COLCOUNTER
#EndRegion XML.au3 - ARRAY Enums
#Region XML.au3 - XML DOM Enumerated Constants
;~ https://msdn.microsoft.com/en-us/library/ms766473(v=vs.85).aspx
Global Const $XML_NODE_ELEMENT = 1
Global Const $XML_NODE_ATTRIBUTE = 2
Global Const $XML_NODE_TEXT = 3
Global Const $XML_NODE_CDATA_SECTION = 4
Global Const $XML_NODE_ENTITY_REFERENCE = 5
Global Const $XML_NODE_ENTITY = 6
Global Const $XML_NODE_PROCESSING_INSTRUCTION = 7
Global Const $XML_NODE_COMMENT = 8
Global Const $XML_NODE_DOCUMENT = 9
Global Const $XML_NODE_DOCUMENT_TYPE = 10
Global Const $XML_NODE_DOCUMENT_FRAGMENT = 11
Global Const $XML_NODE_NOTATION = 12
#EndRegion XML.au3 - XML DOM Enumerated Constants
#Region XML.au3 - readyState Property (DOMDocument)
;~ https://msdn.microsoft.com/en-us/library/ms753702(v=vs.85).aspx
Global Const $XML_DOCUMENT_READYSTATE_LOADING = 1
Global Const $XML_DOCUMENT_READYSTATE_LOADED = 2
Global Const $XML_DOCUMENT_READYSTATE_INTERACTIVE = 3
Global Const $XML_DOCUMENT_READYSTATE_COMPLETED = 4
#EndRegion XML.au3 - readyState Property (DOMDocument)
#Region XML.au3 - Functions - Not yet reviewed
; ===============================================================================================================================
; XMLWrapper functions
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_CreateAttribute
; Description ...: Adds an XML Attribute to specified node.
; Syntax ........: _XML_CreateAttribute(Byref $oXmlDoc, $sXPath, $asAttributeList)
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument or IXMLDOMElement object.
; $sXPath - a string value. The XML tree path from root node (root/child/child..)
; $asAttributeList - an array of strings. Column0=AtributeName, Column1=AtributeValue
; Return values .: On Success - Returns $XML_RET_SUCCESS
; On Failure - Returns $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok, GMK
; Remarks .......:
; Related .......: https://msdn.microsoft.com/en-us/library/ms754616(v=vs.85).aspx
; Link ..........: https://msdn.microsoft.com/en-us/library/ms764615(v=vs.85).aspx
; Example .......: Yes
; ===============================================================================================================================
Func _XML_CreateAttribute(ByRef $oXmlDoc, $sXPath, $asAttributeList)
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
Local $oNode_Selected = _XML_SelectSingleNode($oXmlDoc, $sXPath)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
If Not UBound($asAttributeList) Or UBound($asAttributeList, $UBOUND_COLUMNS) <> 2 Then
Return SetError($XML_ERR_PARAMETER, $XML_EXT_PARAM3, $XML_RET_FAILURE)
EndIf
Local Enum $eAttribute_Name, $eAttribute_Value
Local $oAttribute = Null
#forceref $oAttribute
For $iAttribute_idx = 0 To UBound($asAttributeList) - 1
$oAttribute = $oXmlDoc.createAttribute($asAttributeList[$iAttribute_idx][$eAttribute_Name]) ;, $sNameSpace) ; TODO Check why $sNameSpace
If @error Then Return SetError($XML_ERR_COMERROR, @error, $XML_RET_FAILURE)
$oNode_Selected.SetAttribute($asAttributeList[$iAttribute_idx][$eAttribute_Name], $asAttributeList[$iAttribute_idx][$eAttribute_Value])
If $oXmlDoc.parseError.errorCode Then
Return SetError($XML_ERR_PARSE, $oXmlDoc.parseError.errorCode, $XML_RET_FAILURE)
EndIf
Next
; CleanUp
$oAttribute = Null
$oNode_Selected = Null
Return SetError($XML_ERR_SUCCESS, $XML_EXT_DEFAULT, $XML_RET_SUCCESS)
EndFunc ;==>_XML_CreateAttribute
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_CreateCDATA
; Description ...: Create a CDATA SECTION node directly under root.
; Syntax ........: _XML_CreateCDATA(ByRef $oXmlDoc, $sNode, $sCDATA[, $sNameSpace = ""])
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument object.
; $sNode - a string value. name of node to create
; $sCDATA - a string value. CDATA value
; $sNameSpace - a string value. the namespace to specifiy if the xml uses one.
; Return values .: On Success - Returns $XML_RET_SUCCESS
; On Failure - Returns $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok
; Remarks .......: fixme, won't append to exisiting node. must create new node.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ===============================================================================================================================
Func _XML_CreateCDATA(ByRef $oXmlDoc, $sNode, $sCDATA, $sNameSpace = "")
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
__XML_IsValidObject_DOMDocument($oXmlDoc)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
Local $oNode = $oXmlDoc.createNode($XML_NODE_ELEMENT, $sNode, $sNameSpace)
If @error Then Return SetError($XML_ERR_NODECREATE, @error, $XML_RET_FAILURE)
If IsObj($oNode) Then
Local $oChild = $oXmlDoc.createCDATASection($sCDATA)
$oNode.appendChild($oChild)
If @error Then Return SetError($XML_ERR_NODEAPPEND, @error, $XML_RET_FAILURE)
$oXmlDoc.documentElement.appendChild($oNode)
If @error Then Return SetError($XML_ERR_NODEAPPEND, @error, $XML_RET_FAILURE)
$oChild = Null
Return SetError($XML_ERR_SUCCESS, $XML_EXT_DEFAULT, $XML_RET_SUCCESS)
EndIf
Return SetError($XML_ERR_GENERAL, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndFunc ;==>_XML_CreateCDATA
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_CreateComment
; Description ...: Create a COMMENT node at specified path.
; Syntax ........: _XML_CreateComment(ByRef $oXmlDoc, $sXPath, $sComment)
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument or IXMLDOMElement object.
; $sXPath - a string value. The XML tree path from root node (root/child/child..)
; $sComment - a string value. The comment to add the to the xml file.
; Return values .: On Success - Returns $XML_RET_SUCCESS
; On Failure - Returns $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ===============================================================================================================================
Func _XML_CreateComment(ByRef $oXmlDoc, $sXPath, $sComment)
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
Local $oNode_Selected = _XML_SelectSingleNode($oXmlDoc, $sXPath)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
Local $oChild = $oXmlDoc.createComment($sComment)
$oNode_Selected.insertBefore($oChild, $oNode_Selected.childNodes(0))
If @error Then
Return SetError($XML_ERR_COMERROR, @error, $XML_RET_SUCCESS)
ElseIf $oXmlDoc.parseError.errorCode Then
Return SetError($XML_ERR_PARSE, $oXmlDoc.parseError.errorCode, $XML_RET_FAILURE)
EndIf
Return SetError($XML_ERR_SUCCESS, $XML_EXT_DEFAULT, $XML_RET_SUCCESS) ; TODO Check for what we need to return on success
EndFunc ;==>_XML_CreateComment
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_CreateRootNode
; Description ...: Create node directly under root.
; Syntax ........: _XML_CreateRootNode(ByRef $oXmlDoc, $sNode[, $sData = ""[, $sNameSpace = ""]])
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument object.
; $sNode - a string value. The name of node to create.
; $sData - a string value. The optional value to create
; $sNameSpace - a string value. the namespace to specifiy if the file uses one.
; Return values .: On Success - Returns $XML_RET_SUCCESS
; On Failure - Returns $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok, GMK
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ===============================================================================================================================
Func _XML_CreateRootNode(ByRef $oXmlDoc, $sNode, $sData = "", $sNameSpace = "")
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
__XML_IsValidObject_DOMDocument($oXmlDoc)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
Local $oChild = $oXmlDoc.createNode($XML_NODE_ELEMENT, $sNode, $sNameSpace)
If @error Then Return SetError($XML_ERR_NODECREATE, @error, $XML_RET_FAILURE)
If IsObj($oChild) Then
If $sData <> "" Then $oChild.text = $sData
$oXmlDoc.appendChild($oChild)
If @error Then Return SetError($XML_ERR_NODEAPPEND, @error, $XML_RET_FAILURE)
$oChild = 0
Return SetError($XML_ERR_SUCCESS, $XML_EXT_DEFAULT, $XML_RET_SUCCESS)
EndIf
Return SetError($XML_ERR_GENERAL, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndFunc ;==>_XML_CreateRootNode
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_CreateRootNodeWAttr
; Description ...: Create a child node under root node with attributes.
; Syntax.........: _XML_CreateRootNodeWAttr($sNode, $aAttribute_Names, $aAttribute_Values[, $sData = ""[, $sNameSpace = ""]])
; Parameters ....: $sNode - The node to add with attibute(s)
; $aAttribute_Names - The attribute name(s) -- can be array
; $aAttribute_Values - The attribute value(s) -- can be array
; $sData - The optional value to give the node.
; Return values .: Success $XML_RET_SUCCESS
; Failure - $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok
; Remarks .......: This function requires that each attribute name has a corresponding value.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ===============================================================================================================================
Func _XML_CreateRootNodeWAttr(ByRef $oXmlDoc, $sNode, $aAttribute_Names, $aAttribute_Values, $sData = "", $sNameSpace = "")
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
__XML_IsValidObject_DOMDocument($oXmlDoc)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
Local $oChild_Node = $oXmlDoc.createNode($XML_NODE_ELEMENT, $sNode, $sNameSpace)
If @error Then Return SetError($XML_ERR_NODECREATE, @error, $XML_RET_FAILURE)
If IsObj($oChild_Node) Then
If $sData <> "" Then $oChild_Node.text = $sData
Local $oAttribute = Null
#forceref $oAttribute
If IsArray($aAttribute_Names) And IsArray($aAttribute_Values) Then
If UBound($aAttribute_Names) <> UBound($aAttribute_Values) Then
Return SetError($XML_ERR_GENERAL, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndIf
For $iAttribute_idx = 0 To UBound($aAttribute_Names) - 1
If $aAttribute_Names[$iAttribute_idx] = "" Then
Return SetError($XML_ERR_GENERAL, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndIf
$oAttribute = $oXmlDoc.createAttribute($aAttribute_Names[$iAttribute_idx]) ;, $sNameSpace) ; TODO Check why $sNameSpace
$oChild_Node.SetAttribute($aAttribute_Names[$iAttribute_idx], $aAttribute_Values[$iAttribute_idx])
Next
Else
$oAttribute = $oXmlDoc.createAttribute($aAttribute_Names)
$oChild_Node.SetAttribute($aAttribute_Names, $aAttribute_Values)
EndIf
$oXmlDoc.appendChild($oChild_Node)
If @error Then Return SetError($XML_ERR_NODEAPPEND, @error, $XML_RET_FAILURE)
$oChild_Node = Null
Return SetError($XML_ERR_SUCCESS, $XML_EXT_DEFAULT, $XML_RET_SUCCESS)
EndIf
Return SetError($XML_ERR_GENERAL, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndFunc ;==>_XML_CreateRootNodeWAttr
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_DeleteNode
; Description ...: Deletes XML Node based on XPath input from root node.
; Syntax ........: _XML_DeleteNode(ByRef $oXmlDoc, $sXPath)
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument or IXMLDOMElement object.
; $sXPath - a string value. The XML tree path from root node (root/child/child..)
; Return values .: On Success - Returns $XML_RET_SUCCESS
; On Failure - Returns $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; |0 - No error
; |1 - Deletion error
; |2 - No object passed
; Author ........: Eltorro
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ===============================================================================================================================
Func _XML_DeleteNode(ByRef $oXmlDoc, $sXPath)
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
Local $oNodes_coll = _XML_SelectNodes($oXmlDoc, $sXPath)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
For $oNode_enum In $oNodes_coll
If $oNode_enum.hasChildNodes Then
For $oNode_enum_Child In $oNode_enum.childNodes
If $oNode_enum_Child.nodeType = $XML_NODE_TEXT Then
If StringStripWS($oNode_enum_Child.text, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) = "" Then
$oNode_enum.removeChild($oNode_enum_Child)
EndIf
EndIf
Next
EndIf
$oNode_enum.parentNode.removeChild($oNode_enum)
Next
Return SetError($XML_ERR_SUCCESS, $XML_EXT_DEFAULT, $XML_RET_SUCCESS)
EndFunc ;==>_XML_DeleteNode
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_GetAllAttrib
; Description ...: Get all XML Field(s) attributes based on XPath input from root node.
; Syntax ........: _XML_GetAllAttrib(ByRef $oXmlDoc, $sXPath, ByRef $aName, ByRef $aValue)
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument or IXMLDOMElement object.
; $sXPath - a string value. The XML tree path from root node (root/child/child..)
; Return values .: On Success - Returns array of fields text values (number of items is in [0][0])
; On Failure - Returns $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ===============================================================================================================================
Func _XML_GetAllAttrib(ByRef $oXmlDoc, $sXPath)
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
Local $oNodes_coll = _XML_SelectNodes($oXmlDoc, $sXPath)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
Local $oAttributes_coll = Null
Local $aResponse[1][$XMLATTR_COLCOUNTER]
For $oNode_enum In $oNodes_coll
$oAttributes_coll = $oNode_enum.attributes
If ($oAttributes_coll.length) = 0 Then
ContinueLoop
Return SetError($XML_ERR_GENERAL, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndIf
ReDim $aResponse[$oAttributes_coll.length + 2][$XMLATTR_COLCOUNTER]
For $iAttribute_idx = 0 To $oAttributes_coll.length - 1
$aResponse[$iAttribute_idx + 1][$XMLATTR_COLNAME] = $oAttributes_coll.item($iAttribute_idx).nodeName
$aResponse[$iAttribute_idx + 1][$XMLATTR_COLVALUE] = $oAttributes_coll.item($iAttribute_idx).Value
Next
Next
$aResponse[0][0] = $oAttributes_coll.length
Return SetError($XML_ERR_SUCCESS, $XML_EXT_DEFAULT, $aResponse)
EndFunc ;==>_XML_GetAllAttrib
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_GetChildren
; Description ...: Selects XML child Node(s) of an element based on XPath input from root node and returns there text values.
; Syntax ........: _XML_GetChildren(ByRef $oXmlDoc, $sXPath)
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument or IXMLDOMElement object.
; $sXPath - a string value. The XML tree path from root node (root/child/child..)
; Return values .: On Success - Returns an array where:
; |$array[0][0] = Size of array
; |$array[1][0] = Name
; |$array[1][1] = Text
; |$array[1][2] = NameSpaceURI
; |...
; |$array[n][0] = Name
; |$array[n][1] = Text
; |$array[n][2] = NamespaceURI
; On Failure - $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ===============================================================================================================================
Func _XML_GetChildren(ByRef $oXmlDoc, $sXPath)
; Error handler, automatic cleanup at end of function
Local $oXML_COM_ErrorHandler = ObjEvent("AutoIt.Error", __XML_ComErrorHandler_InternalFunction)
#forceref $oXML_COM_ErrorHandler
__XML_IsValidObject_DOMDocument($oXmlDoc)
If @error Then Return SetError(@error, @extended, $XML_RET_FAILURE)
Local $oNode_Selected = _XML_SelectSingleNode($oXmlDoc, $sXPath)
If @error Then
Return SetError(@error, @extended, $XML_RET_FAILURE)
ElseIf $oNode_Selected.hasChildNodes() Then
Local $iResponseDimSize = 0
Local $aResponse[1][3] = [[$iResponseDimSize, '', '']]
For $oNode_enum_Child In $oNode_Selected.childNodes()
If $oNode_enum_Child.nodeType() = $XML_NODE_ELEMENT And $oNode_enum_Child.hasChildNodes() Then
For $oNode_enum_Descendant In $oNode_enum_Child.childNodes()
If $oNode_enum_Descendant.nodeType() = $XML_NODE_TEXT Then
$iResponseDimSize = UBound($aResponse, 1)
ReDim $aResponse[$iResponseDimSize + 1][3]
$aResponse[$iResponseDimSize][0] = $oNode_enum_Descendant.parentNode.baseName
$aResponse[$iResponseDimSize][1] = $oNode_enum_Descendant.text
$aResponse[$iResponseDimSize][2] = $oNode_enum_Descendant.NamespaceURI
; TODO Check
; _XML_Array_AddName($aResponse, $oNode_enum_Child.baseName)
EndIf
Next
EndIf
Next
$aResponse[0][0] = $iResponseDimSize
; TODO Description for @extended
Return SetError($XML_ERR_SUCCESS, $iResponseDimSize, $aResponse)
EndIf
Return SetError($XML_ERR_NOCHILDMATCH, $XML_EXT_DEFAULT, $XML_RET_FAILURE)
EndFunc ;==>_XML_GetChildren
; #FUNCTION# ====================================================================================================================
; Name ..........: _XML_GetChildText
; Description ...: Selects XML child Node(s) of an element based on XPath input from root node.
; Syntax ........: _XML_GetChildText(ByRef $oXmlDoc, $sXPath)
; Parameters ....: $oXmlDoc - [in/out] an object. A valid DOMDocument or IXMLDOMElement object.
; $sXPath - a string value. The XML tree path from root node (root/child/child..)
; Return values .: On Success - Returns an array of Node's names and text.
; On Failure - Returns $XML_RET_FAILURE and sets the @error flag to non-zero (look in #Region XML.au3 - ERROR Enums)
; Author ........: Eltorro
; Modified ......: mLipok
; Remarks .......: