/
_XMLDomWrapper.au3
1752 lines (1742 loc) · 72.5 KB
/
_XMLDomWrapper.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
; =======================================================================
; Project Manager 3.0 Preprocessed - Date 25:04:2007 Time 14:28
; =======================================================================
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language: English
; Description: Functions that assist with using xml files
; Stephen Podhajecki <gehossafats@netmdc.com>
; Dec 15, 2005, Update Jan10,2006, Update Feb 5,8,14-15, 2006
; Feb 24, 2006 Updated _XMLCreateCDATA, code cleaned up Gary Frost (custompcs@charter.net)
; Feb 24, 2006 bug fix in re-init COM error handler, rewrote _XMLCreateChildNodeWAttr()
; Jun 20, 2006 Added count to index[0] of the _XMLGetValue return value
; Jun 26, 2006 Changed _XMLCreateFile to include option flag for UTF-8 encoding
; Jun 29, 2006 Added count to index[0] of the _XMLGetValue return
; Changed _XMLFileOpen and _XMLFileCreate
; Mar 30, 2007 Rewrote _AddFormat function to break up tags( no indentation)
; Added _XMLTransform() which runs the document against a xsl(t) style sheet for indentation.
; Changed _XMLCreateRootChildWAttr() to use new formatting
; Changed _XMLChreateChildNode() to use new formatting
; Apr 02, 2007 Added _XMLReplaceChild()
; Apr 03, 2007 Changed other node creating function to use new formatting
; Changed _XMLFileOpen() _XMLFileCreate to take an optional version number of MSXML to use.
; Changed _XMLFileOpen() _XMLFileCreate find latest MSXML version logic.
; Apr 24, 2007 Fixed _XMLCreateChileNodeWAttr() - Instead of removal, It points to the function that replaced it.
; Apr 25, 2007 Added _XMLCreateAttrib()
; Fixed bug with _XMLCreateRootNodeWAttr , _XMLCreateChild[Node]WAttr() where an extra node with same name was added.
; Stripped extrenous comments.
; Removed dependency on Array.au3 (I added the func from Array.au3 and renamed it to avoid conflicts.)
; May 03, 2007 Changed method of msxml version lookup. Updated api call tips.
; May 11, 2007 Fixed missing \
; Jun 08, 2007 Fixed Namespace issue with _XMLCreateChildNode() and _XMLCreateChildNodeWAttr()
; Jun 12, 2007 Added workaround for MSXML6 to parse file with DTD's
; Jun 13, 2007 Fixed bug in _XMLGetField() where all text was returned in one node.
; Actually this is not a bug, because it is the way that WC3 says it will be returned
; However, it will now return in a way that is expected.
; _XMLGetValue now returns just the text associated with the node or empty string.
; Jul 20, 2007 Fixed bug where failure to open the xml file would return an empty xml object, it now returns 0(no object).
; Added object check to all applicable functions.
; Aug 08, 2007 Add a _XMLSetAutoSave() to turn off/on forced saving within each function. --Thanks drlava
; Added check for previous COM error handler. --Thanks Lukasz Suleja
; Aug 27,2007 Changed property setting order for _XMLFileOpen. The previous order was causing a problem with default namespaces.
; -- It seems that "selectionLanguage" needs to be declared before some other properties.
; Aug 31,2007 Fixed bug where _XMLUpdateField would inadvertantly erase child nodes.
; Sep 07,2007 Fixed _XMLDeleteNode bug where non-existant node cause COM error.
; Added _XMLNodeExist function to check for the existence of node or nodes matching the specified path
; Jan 05,2008 Fixed documentation problem in function header with _XMLGetAttrib.
; Feb 25,2008 Fixed dimensioning bug in _XMLGetChildren --Thanks oblique
; Mar 05,2008 Return values fixed for the following functions: --Thanks oblique
; _XMLFileOpen ,_XMLLoadXML,_XMLCreateFile,
; Documentation fixed for _XMLGetNodeCount,_XMLGetChildren --Thanks oblique
; Mar 07,2008 Small changes.
; Fixed an issue point out by lgr.
; ------------------------------------------------------------------------------
;===============================================================================
; XML DOM Wrapper functions
;
; These funtions require BETA as they need support for COM
;
;===============================================================================
#cs defs to add to au3.api
_XMLCreateFile($sPath, $sRootNode, [$bOverwrite = False]) Creates an XML file with the given name and root.(Requires: #include <_XMLDomWrapper.au3>)
_XMLFileOpen($sXMLFile,[$sNamespace=""],[$ver=-1]) Creates an instance of an XML file.(Requires: #include <_XMLDomWrapper.au3>)
;==============================================================================
_XMLGetChildNodes ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
_XMLGetNodeCount ( strXPath, strQry = "", iNodeType = 1 ) Get node count for specified path and type. (Requires: #include <_XMLDomWrapper.au3>)
_XMLGetPath ( strXPath ) Returns a nodes full path based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
;==============================================================================
_XMLSelectNodes ( strXPath ) Selects XML Node(s) based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
_XMLGetField ( strXPath ) Get XML Field(s) based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
_XMLGetValue ( strXPath ) Get XML Field based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
_XMLGetChildText ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
_XMLUpdateField ( strXPath, strData ) Update existing node(s) based on XPath specs.(Requires: #include <_XMLDomWrapper.au3>)
_XMLReplaceChild ( objOldNode, objNewNode, ns = "" ) Replaces a node with a new node. (Requires: #include <_XMLDomWrapper.au3>)
;==============================================================================
_XMLDeleteNode ( strXPath ) Delete specified XPath node.(Requires: #include <_XMLDomWrapper.au3>)
_XMLDeleteAttr ( strXPath, strAttrib ) Delete attribute for specified XPath(Requires: #include <_XMLDomWrapper.au3>)
_XMLDeleteAttrNode ( strXPath, strAttrib ) Delete attribute node for specified XPath(Requires: #include <_XMLDomWrapper.au3>)
;==============================================================================
_XMLGetAttrib ( strXPath, strAttrib, strQuery = "" ) Get XML attribute based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
_XMLGetAllAttrib ( strXPath, ByRef aName, ByRef aValue, strQry = "" ) Get all XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
_XMLGetAllAttribIndex ( strXPath, ByRef aName, ByRef aValue, strQry = "", NodeIndex = 0 ) Get all XML Field(s) attributes based on Xpathn and specific index.(Requires: #include <_XMLDomWrapper.au3>)
_XMLSetAttrib ( strXPath, strAttrib, strValue = "" ) Set XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
;==============================================================================
_XMLCreateCDATA ( strNode, strCDATA, strNameSpc = "" ) Create a CDATA SECTION node directly under root. (Requires: #include <_XMLDomWrapper.au3>)
_XMLCreateComment ( strNode, strComment ) Create a COMMENT node at specified path.(Requires: #include <_XMLDomWrapper.au3>)
_XMLCreateAttrib ( strXPath,strAttrName,strAttrValue="" ) Creates an attribute for the specified node. (Requires: #include <_XMLDomWrapper.au3>)
;==============================================================================
_XMLCreateRootChild ( strNode, strData = "", strNameSpc = "" ) Create node directly under root.(Requires: #include <_XMLDomWrapper.au3>)
_XMLCreateRootNodeWAttr ( strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under root node with attributes.(Requires: #include <_XMLDomWrapper.au3>)
_XMLCreateChildNode ( strXPath, strNode, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node.(Requires: #include <_XMLDomWrapper.au3>)
_XMLCreateChildWAttr ( strXPath, strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node with Attributes. (Requires: #include <_XMLDomWrapper.au3>)
;==============================================================================
_XMLSchemaValidate ( sXMLFile, ns, sXSDFile ) _XMLSchemaValidate($sXMLFile, $ns, $sXSDFile) Validate a document against a DTD. (Requires: #include <_XMLDomWrapper.au3>)
_XMLGetDomVersion ( ) Returns the XSXML version currently in use. (Requires: #include <_XMLDomWrapper.au3>)
_XMLError ( sError = "" ) Sets or Gets XML error message generated by XML functions.(Requires: #include <_XMLDomWrapper.au3>)
_XMLUDFVersion ( ) eturns the UDF Version number. (Requires: #include <_XMLDomWrapper.au3>)
_XMLTransform ( oXMLDoc, Style = "",szNewDoc="" ) Transfroms the document using built-in sheet or xsl file passed to function. (Requires: #include <_XMLDomWrapper.au3>)
_XMLNodeExists( $strXPath) Checks for the existence of the specified path. (Requires: #include <_XMLDomWrapper.au3>)
#ce
;===============================================================================
;Global variables
Global Const $_XMLUDFVER = "1.0.3.87"
Global Const $NODE_ELEMENT = 1
Global Const $NODE_ATTRIBUTE = 2
Global Const $NODE_TEXT = 3
Global Const $NODE_CDATA_SECTION = 4
Global Const $NODE_ENTITY_REFERENCE = 5
Global Const $NODE_ENTITY = 6
Global Const $NODE_PROCESSING_INSTRUCTION = 7
Global Const $NODE_COMMENT = 8
Global Const $NODE_DOCUMENT = 9
Global Const $NODE_DOCUMENT_TYPE = 10
Global Const $NODE_DOCUMENT_FRAGMENT = 11
Global Const $NODE_NOTATION = 12
Global $strFile
Global $objDoc
Global $oXMLMyError ;COM error handler OBJ ; Initialize SvenP 's error handler
Global $sXML_error
Global $debugging
Global $DOMVERSION = -1
Global $bXMLAUTOSAVE = True
;===============================================================================
;UDF functions
;===============================================================================
; Function Name: _XMLFileOpen
; Description: Creates an instance of an XML file.
; Parameter(s): $strXMLFile - the XML file to open
; $strNameSpc - the namespace to specifiy if the file uses one.
; $iVer - specifically try to use the version supplied here.
; $bValOnParse - validate the document as it is being parsed
; Syntax: _XMLFileOpen($strXMLFile, [$strNameSpc], [$iVer], [$bValOnParse] )
; Return Value(s): On Success - 1
; On Failure - -1 and set
; @Error to:
; 0 - No error
; 1 - Parse error, @Extended = MSXML reason
; 2 - No object
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
;===============================================================================
Func _XMLFileOpen($strXMLFile, $strNameSpc = "", $iVer = -1, $bValOnParse = True)
;==== pick your poison
If $iVer <> -1 Then
If $iVer > -1 And $iVer < 7 Then
$objDoc = ObjCreate("Msxml2.DOMDocument." & $iVer & ".0")
If IsObj($objDoc) Then
$DOMVERSION = $iVer
EndIf
Else
MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $iVer)
SetError(1)
Return 0
EndIf
Else
For $x = 8 To 0 Step - 1
If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then
$objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0")
If IsObj($objDoc) Then
$DOMVERSION = $x
ExitLoop
EndIf
EndIf
Next
EndIf
If Not IsObj($objDoc) Then
_XMLError("Error: MSXML not found. This object is required to use this program.")
SetError(2)
Return -1
EndIf
;Thanks Lukasz Suleja
$oXMLMyError = ObjEvent("AutoIt.Error")
If $oXMLMyError = "" Then
$oXMLMyError = ObjEvent("AutoIt.Error", "_XMLCOMEerr") ; ; Initialize SvenP 's error handler
EndIf
$strFile = $strXMLFile
$objDoc.async = False
$objDoc.preserveWhiteSpace = True
$objDoc.validateOnParse = $bValOnParse
if $DOMVERSION > 4 Then $objDoc.setProperty ("ProhibitDTD",false)
$objDoc.Load ($strFile)
$objDoc.setProperty ("SelectionLanguage", "XPath")
$objDoc.setProperty ("SelectionNamespaces", $strNameSpc)
if $objDoc.parseError.errorCode >0 Then consoleWrite($objDoc.parseError.reason&@LF)
If $objDoc.parseError.errorCode <> 0 Then
_XMLError("Error opening specified file: " & $strXMLFile & @CRLF & $objDoc.parseError.reason)
;Tom Hohmann 2008/02/29
SetError(1,$objDoc.parseError.errorCode,-1)
$objDoc = 0
Return -1
EndIf
;Tom Hohmann 2008/02/29
Return 1
EndFunc ;==>_XMLFileOpen
;===============================================================================
; Function Name: _XMLLoadXML
; Description: Creates an instance for a string of XML .
; Parameters: $strXML - The XML to load into the document
; Syntax: _XMLLoadXML($strXML)
; Return Value(s): On Success - 1
; On Failure - -1 and set @error to
; 1 - failed to create object, @Extended = MSXML reason
; 2 - no object found (MSXML required for _XML functions
;
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>,Lukasz Suleja,Tom Hohmann
;===============================================================================
Func _XMLLoadXML($strXML,$strNameSpc="", $iVer = -1, $bValOnParse = True)
If $iVer <> -1 Then
If $iVer > -1 And $iVer < 7 Then
$objDoc = ObjCreate("Msxml2.DOMDocument." & $iVer & ".0")
If IsObj($objDoc) Then
$DOMVERSION = $iVer
EndIf
Else
MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $iVer)
SetError(1)
Return 0
EndIf
Else
For $x = 8 To 0 Step - 1
If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then
$objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0")
If IsObj($objDoc) Then
$DOMVERSION = $x
ExitLoop
EndIf
EndIf
Next
EndIf
If Not IsObj($objDoc) Then
_XMLError("Error: MSXML not found. This object is required to use this program.")
SetError(2)
Return -1
EndIf
;Thanks Lukasz Suleja
$oXMLMyError = ObjEvent("AutoIt.Error")
If $oXMLMyError = "" Then
$oXMLMyError = ObjEvent("AutoIt.Error", "_XMLCOMEerr") ; ; Initialize SvenP 's error handler
EndIf
$objDoc.async = False
$objDoc.preserveWhiteSpace = True
$objDoc.validateOnParse = $bValOnParse
if $DOMVERSION > 4 Then $objDoc.setProperty ("ProhibitDTD",false)
$objDoc.LoadXml ($strXML)
$objDoc.setProperty ("SelectionLanguage", "XPath")
$objDoc.setProperty ("SelectionNamespaces", $strNameSpc); "xmlns:ms='urn:schemas-microsoft-com:xslt'"
If $objDoc.parseError.errorCode <> 0 Then
_XMLError("Error loading the XML data: " & @CRLF & $objDoc.parseError.reason)
;Tom Hohmann 2008/02/29
SetError(1,$objDoc.parseError.errorCode, -1)
Return -1
EndIf
;Tom Hohmann 2008/02/29
Return 1
EndFunc ;==>_MSXMLLoadXML
;===============================================================================
; Function Name: _XMLCreateFile
; Description: Create a new blank metafile with header.
; Parameter(s): $strPath - The xml filename with full path to create
; $strRoot - The root of the xml file to create
; $bOverwrite - boolean flag to auto overwrite existing file of same name.
; $bUTF8 - boolean flag to specify UTF-8 encoding in header.
; Syntax: _XMLCreateFile($strPath,$strRoot,[$bOverwrite],[$bUTF8])
; Return Value(s): On Success - 1
; On Failure - -1 and sets
; @Error to:
; 0 = No error
; 1 = Failed to create file
; 2 = No object
; 3 = File creation failed MSXML error
; 4 = File exists
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
;===============================================================================
Func _XMLCreateFile($strPath, $strRoot, $bOverwrite = False, $bUTF8 = False, $ver = -1)
Local $retval, $fe, $objPI, $objDoc, $rootElement
$fe = FileExists($strPath)
If $fe And Not $bOverwrite Then
$retval = (MsgBox(4097, "File Exists:", "The specified file exits." & @CRLF & "Click OK to overwrite file or cancel to exit."))
If $retval = 1 Then
FileCopy($strPath, $strPath & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & "-" & @SEC & ".bak", 1)
FileDelete($strPath)
$fe = False
Else
_XMLError("Error failed to create file: " & $strPath & @CRLF & "File exists.")
SetError(4)
Return -1
EndIf
Else
FileCopy($strPath, $strPath & ".old", 1)
FileDelete($strPath)
$fe = False
EndIf
If $fe = False Then
If $ver <> -1 Then
If $ver > -1 And $ver < 7 Then
$objDoc = ObjCreate("Msxml2.DOMDocument." & $ver & ".0")
If IsObj($objDoc) Then
$DOMVERSION = $ver
EndIf
Else
MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $ver)
SetError(3)
Return 0
EndIf
Else
For $x = 8 To 0 Step - 1
If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then
$objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0")
If IsObj($objDoc) Then
$DOMVERSION = $x
ExitLoop
EndIf
EndIf
Next
EndIf
If Not IsObj($objDoc) Then
Return SetError(2)
EndIf
If $bUTF8 Then
$objPI = $objDoc.createProcessingInstruction ("xml", "version=""1.0"" encoding=""UTF-8""")
Else
$objPI = $objDoc.createProcessingInstruction ("xml", "version=""1.0""")
EndIf
$objDoc.appendChild ($objPI)
$rootElement = $objDoc.createElement ($strRoot)
$objDoc.documentElement = $rootElement
$objDoc.save ($strPath)
If $objDoc.parseError.errorCode <> 0 Then
_XMLError("Error Creating specified file: " & $strPath)
; Tom Hohmann 2008/02/29
SetError(1, $objDoc.parseError.errorCode, -1)
Return -1
EndIf
Return 1
Else
_XMLError("Error! Failed to create file: " & $strPath)
SetError(1)
Return 0
EndIf
Return 1
EndFunc ;==>_XMLCreateFile
;===============================================================================
; Function Name: _XMLSelectNodes
; Description: Selects XML Node(s) based on XPath input from root node.
; Parameter(s): $strXPath - xml tree path from root node (root/child/child..)
; Syntax: _XMLSelectNode($strXPath)
; Return Value(s): On Success - An array of Nodes(count is in first element)
; On Failure - -1 and set @Error = 1
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
;===============================================================================
Func _XMLSelectNodes($strXPath)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLSelectNodes")
Return SetError(2,0,-1)
EndIf
Local $objNode, $objNodeList, $arrResponse[1], $xmlerr
$objNodeList = $objDoc.selectNodes ($strXPath)
If Not IsObj($objNodeList) Then
_XMLError("\nNo matching nodes found")
Return SetError(1,0,-1)
EndIf
If $objNodeList.length < 1 Then
_XMLError("\nNo matching nodes found")
Return SetError(1,0,-1)
EndIf
For $objNode In $objNodeList
_XMLArrayAdd($arrResponse, $objNode.nodeName)
_DebugWrite($objNode.nodeName)
_DebugWrite($objNode.namespaceURI)
Next
$arrResponse[0] = $objNodeList.length
Return $arrResponse
_XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr)
Return SetError(1,0,-1)
EndFunc ;==>_XMLSelectNodes
;===============================================================================
; Function Name: _XMLGetField
; Description: Get XML Field(s) based on XPath input from root node.
; Parameter(s): $path xml tree path from root node (root/child/child..)
; Syntax: _XMLGetField($path)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s): On Success An array of fields text values(count is in first element)
; On Failure -1 set @Error = 1
;===============================================================================
Func _XMLGetField($strXPath)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLGetField")
Return SetError(1,2,-1)
EndIf
Local $objNodeList, $arrResponse[1], $xmlerr, $szNodePath
$objNodeList = $objDoc.selectSingleNode ($strXPath)
If Not IsObj($objNodeList) Then
_XMLError("\nNo Matching Nodes found")
$arrResponse[0] = 0
Return SetError(2,0,-1)
EndIf
If $objNodeList.hasChildNodes () Then
Local $count = $objNodeList.childNodes.length
For $x =1 to $count
$objChild = $objNodeList.childNodes($x)
_DebugWrite("ParentNode="&$objNodeList.parentNode.nodeType)
If $objNodeList.parentNode.nodeType =$NODE_DOCUMENT Then
$szNodePath="/"&$objNodeList.baseName &"/*["&$x&"]"
Else
$szNodePath = $objNodeList.baseName &"/*["&$x&"]"
EndIf
$aRet = _XMLGetValue($szNodePath)
If IsArray($aRet) Then
If UBound($aRet) > 1 Then
_XMLArrayAdd($arrResponse, $aRet[1])
_DebugWrite("GetField>Text:" & $aRet[1])
EndIf
Else
_XMLArrayAdd($arrResponse, "")
_DebugWrite("GetField>Text:" & "")
EndIf
Next
$arrResponse[0] = UBound($arrResponse) - 1
Return $arrResponse
Else
$arrResponse[0] = 0
_XMLError("\nNo Child Nodes found")
Return SetError(1,0,-1)
EndIf
_XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr)
Return SetError(1,0,-1)
EndFunc ;==>_XMLGetField
;===============================================================================
; Function Name: _XMLGetValue
; Description: Get XML values based on XPath input from root node.
; Parameter(s): $strXPath - xml tree path from root node (root/child/child..)
; Syntax: _XMLGetValue($strXPath)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s): On Success An array of fields text values(count is in first element)
; On Failure -1 set
; @Error = 1
; @Extended to:
; 0 = No matching node
; 1 = No object passed
;===============================================================================
Func _XMLGetValue($strXPath)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLGetValue")
Return SetError(1,1,-1)
EndIf
Local $objNodeList, $arrResponse[1], $objNodeChild, $xmlerr
_DebugWrite("GetValue>$strXPath:"&$strXPath)
$objNodeList = $objDoc.documentElement.selectNodes ($strXPath)
If $objNodeList.length > 0 Then
_DebugWrite("GetValue list length:" & $objNodeList.length)
For $objNode In $objNodeList
If $objNode.hasChildNodes () = False Then
_XMLArrayAdd($arrResponse, $objNode.nodeValue)
Else
For $objNodeChild In $objNode.childNodes ()
If $objNodeChild.nodeType = $NODE_CDATA_SECTION Then
_XMLArrayAdd($arrResponse, $objNodeChild.data)
_DebugWrite("GetValue>CData:" & $objNodeChild.data)
ElseIf $objNodeChild.nodeType = $NODE_TEXT Then
_XMLArrayAdd($arrResponse, $objNodeChild.Text)
_DebugWrite("GetValue>Text:" & $objNodeChild.Text)
EndIf
Next
EndIf
Next
$arrResponse[0] = UBound($arrResponse) - 1
Return $arrResponse
Else
$xmlerr = @CRLF & "No matching node(s)found!"
Return SetError(1,0,-1)
EndIf
_XMLError("Error Retrieving: " & $strXPath & $xmlerr)
Return SetError(1,0, -1)
EndFunc ;==>_XMLGetValue
;===============================================================================
; Function Name: _XMLDeleteNode
; Description: Deletes XML Node based on XPath input from root node.
; Parameter(s): $path xml tree path from root node (root/child/child..)
; Syntax: _XMLDeleteNode($path)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s): On Success 1
; On Failure -1 and Sets
; @Error to:
; 0 = No error
; 1 = Deletion error
; 2 = No object passed
;===============================================================================
Func _XMLDeleteNode($strXPath)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLDeleteNode")
Return SetError(2,0,-1)
EndIf
Local $objNode, $xmlerr
$objNode = $objDoc.selectNodes ($strXPath)
If Not IsObj($objNode) Then $xmlerr = @CRLF & "Node Not found"
if @error = 0 Then
For $objChild in $objNode
ConsoleWrite("Delete node " & $objChild.nodeName & @LF)
$objChild.parentNode.removeChild ($objChild)
Next
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
Return 1
EndIf
_XMLError("Error Deleting Node: " & $strXPath & $xmlerr)
Return SetError(1,0,-1)
EndFunc ;==>_XMLDeleteNode
;===============================================================================
; Function Name: _XMLDeleteAttr
; Description: Delete XML Attribute based on XPath input from root node.
; Parameter(s): $strXPath xml tree path from root node (root/child/child..)
; $strAttribute The attribute node to delete
; Syntax: _XMLDeleteAttr($strPath,$strAttribute)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s): On Success 1
; On Failure -1 and sets
; @Error to:
; 0 = No error
; 1 = Error removing attribute
; 2 = No object
;===============================================================================
Func _XMLDeleteAttr($strXPath, $strAttrib)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLDeleteAttr")
Return SetError(2,0,-1)
EndIf
Local $objNode, $objAttr, $xmlerr
$objNode = $objDoc.selectSingleNode ($strXPath)
If IsObj($objNode) Then
$objAttr = $objNode.getAttributeNode ($strAttrib)
If Not (IsObj($objAttr)) Then
_XMLError("Attribute " & $strAttrib & " does not exist!")
Return SetError(2,0,-1)
EndIf
$objAttr = $objNode.removeAttribute ($strAttrib)
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
Return 1
EndIf
_XMLError("Error Removing Attribute: " & $strXPath & " - " & $strAttrib & @CRLF & $xmlerr)
$xmlerr = ""
Return SetError(1,0,-1)
EndFunc ;==>_XMLDeleteAttr
;===============================================================================
; Function Name: _XMLDeleteAttrNode
; Description: Delete XML Attribute node based on XPath input from root node.
; Parameter(s): $strXpath xml tree path from root node (root/child/child..)
; $strAttribute The attribute node to delete
; Syntax: _XMLDeleteAttrNode($strXPath,$strAttribute)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s): On Success 1
; On Failure -1 and sets
; @Error to:
; 0 = No error
; 1 = Error removing node
; 2 = No object
;===============================================================================
Func _XMLDeleteAttrNode($strXPath, $strAttrib)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLDeleteAttrNode")
Return SetError(2,0,-1)
EndIf
Local $objNode, $objAttr, $xmlerr
$objNode = $objDoc.selectSingleNode ($strXPath)
If Not IsObj($objNode) Then
_XMLError("\nSpecified node not found!")
Return SetError(2,0,-1)
EndIf
$objAttr = $objNode.removeAttributeNode ($objNode.getAttributeNode ($strAttrib))
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
If Not (IsObj($objAttr)) Then
_XMLError("\nUnspecified error:!")
Return SetError(1,0,-1)
EndIf
Return 1
EndFunc ;==>_XMLDeleteAttrNode
;===============================================================================
; Function Name: _XMLGetAttrib
; Description: Get XML Field based on XPath input from root node.
; Parameter(s): $path xml tree path from root node (root/child/child..)
; Syntax: _XMLGetAttrib($path,$attrib)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s): On Success The attribute value.
; On Failure -1 and sets
; @Error to:
; 0 = No error
; 1 = Attribute not found.
; 2 = No object
;===============================================================================
Func _XMLGetAttrib($strXPath, $strAttrib, $strQuery = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLGetAttrib")
Return SetError(2,0,-1)
EndIf
;Local $objNodeList, $arrResponse[1], $i, $xmlerr, $objAttr
Local $objNodeList, $arrResponse, $i, $xmlerr, $objAttr
$objNodeList = $objDoc.documentElement.selectNodes ($strXPath & $strQuery)
_DebugWrite("Get Attrib length= " & $objNodeList.length)
If $objNodeList.length > 0 Then
For $i = 0 To $objNodeList.length - 1
$objAttr = $objNodeList.item ($i).getAttribute ($strAttrib)
$arrResponse = $objAttr
_DebugWrite("RET>>" & $objAttr)
Next
Return $arrResponse
EndIf
$xmlerr = "\nNo qualified items found"
_XMLError("Attribute " & $strAttrib & " not found for: " & $strXPath & $xmlerr)
Return SetError(1,0,-1)
EndFunc ;==>_XMLGetAttrib
;===============================================================================
; Function Name: _XMLSetAttrib
; Description: Set XML Field(s) based on XPath input from root node.
; Parameter(s): $path xml tree path from root node (root/child/child..)
; $attrib the attribute to set.
; $value the value to give the attribute defaults to ""
; Syntax: _XMLSetAttrib($path,$attrib,$value)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) array of fields text values
; on error returns -1 and sets error to 1
;===============================================================================
Func _XMLSetAttrib($strXPath, $strAttrib, $strValue = "", $iIndex =-1)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLSetAttrib")
Return SetError(1,8,-1)
EndIf
Local $objNodeList, $arrResponse[1], $i
$objNodeList = $objDoc.selectNodes ($strXPath)
_DebugWrite(" Node list Length: " & $objNodeList.length)
If @error = 0 And $objNodeList.length > 0 Then
If $iIndex > 0 Then
$arrResponse[0] = $objNodeList.item ($iIndex).SetAttribute ($strAttrib, $strValue)
Else
ReDim $arrResponse[$objNodeList.length]
For $i = 0 To $objNodeList.length - 1
$arrResponse[$i] = $objNodeList.item ($i).SetAttribute ($strAttrib, $strValue)
If $objDoc.parseError.errorCode <> 0 Then ExitLoop
Next
EndIf
If $objDoc.parseError.errorCode <> 0 Then
_XMLError("Error setting attribute for: " & $strXPath & @CRLF & $objDoc.parseError.reason)
Return SetError(1,$objDoc.parseError.errorCode,-1)
EndIf
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
Return $arrResponse
EndIf
_XMLError("Error failed to set attribute for: " & $strXPath & @CRLF)
SetError(1)
Return -1
EndFunc ;==>_XMLSetAttrib
;===============================================================================
; Function Name: _XMLGetAllAttrib
; Description: Get all XML Field(s) attributes based on XPath input from root node.
; Parameter(s): $path xml tree path from root node (root/child/child..)
; $query the query string in xml format
; $names the array to return the attrib names
; $value the array to return the attrib values
; [$query] DOM compliant query string (not really necessary as it becomes
;part of the path
; Syntax: _XMLGetAllAttrib($path,$query)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) array of fields text values(number of items is in [0][0]
; on error set error to 1 and returns -1
;===============================================================================
Func _XMLGetAllAttrib($strXPath, ByRef $aName, ByRef $aValue, $strQry = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLGetAllAttrib")
Return SetError(1,9,-1)
EndIf
Local $objNodeList, $objQueryNodes, $objNode, $arrResponse[2][1], $i
$objQueryNodes = $objDoc.selectNodes ($strXPath & $strQry)
If $objQueryNodes.length > 0 Then
For $objNode In $objQueryNodes
$objNodeList = $objNode.attributes
If ($objNodeList.length) Then
_DebugWrite("Get all attrib " & $objNodeList.length)
ReDim $arrResponse[2][$objNodeList.length + 2]
ReDim $aName[$objNodeList.length]
ReDim $aValue[$objNodeList.length]
For $i = 0 To $objNodeList.length - 1
$arrResponse[0][$i + 1] = $objNodeList.item ($i).nodeName
$arrResponse[1][$i + 1] = $objNodeList.item ($i).Value
$aName[$i] = $objNodeList.item ($i).nodeName
$aValue[$i] = $objNodeList.item ($i).Value
Next
Else
_XMLError("No Attributes found for node")
Return SetError(1,0, -1)
EndIf
Next
$arrResponse[0][0] = $objNodeList.length
Return $arrResponse
EndIf
_XMLError("Error retrieving attributes for: " & $strXPath & @CRLF)
return SetError(1,0 ,-1)
; EndIf
EndFunc ;==>_XMLGetAllAttrib
;===============================================================================
; Function Name: _XMLUpdateField
; Description: Update existing node(s) based on XPath specs.
; Parameter(s): $path Path from root node
; $new_data Data to update node with
; Syntax: _XMLUpdateField($path,$new_data)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) on error set error to 1 and returns -1
;===============================================================================
Func _XMLUpdateField($strXPath, $strData)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLUpdateField")
Return SetError(1,9,-1)
EndIf
Local $objField, $bUpdate, $objNode
#forceref $objField
$objField = $objDoc.selectSingleNode ($strXPath)
If IsObj($objField) Then
If $objField.hasChildNodes Then
For $objChild In $objField.childNodes ()
If $objChild.nodetype = $NODE_TEXT Then
$objChild.Text = $strData
$bUpdate = True
ExitLoop
EndIf
Next
EndIf
if $bUpdate = False Then
$objNode = $objDoc.createTextNode($strData)
$objField.appendChild($objNode)
EndIf
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
$objField = ""
Return
EndIf
_XMLError("Failed to update field for: " & $strXPath & @CRLF)
Return SetError(1,0,-1)
EndFunc ;==>_XMLUpdateField
;===============================================================================
; Function Name: _XMLCreateCDATA
; Description: Create a CDATA SECTION node directly under root.
; Parameter(s): $node name of node to create
; $data CDATA value
; Syntax: _XMLCreateCDATA($node,$data)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s):on error set error to 1 and returns -1
; fixme, won't append to exisiting node. must create new node.
;===============================================================================
Func _XMLCreateCDATA($strNode, $strCDATA, $strNameSpc = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLCreateCDATA")
Return SetError(1,10,-1)
EndIf
Local $objChild, $objNode
$objNode = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
If IsObj($objNode) Then
If Not ($objNode.hasChildNodes ()) Then
_AddFormat($objDoc, $objNode)
EndIf
$objChild = $objDoc.createCDATASection ($strCDATA)
$objNode.appendChild ($objChild)
$objDoc.documentElement.appendChild ($objNode)
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
_AddFormat($objDoc)
$objChild = ""
Return 1
EndIf
_XMLError("Failed to create CDATA Section: " & $strNode & @CRLF)
Return SetError(1, 0 ,-1)
EndFunc ;==>_XMLCreateCDATA
;===============================================================================
; Function Name: _XMLCreateComment
; Description: Create a COMMENT node at specified path.
; Parameter(s): $node name of node to create
; $comment the comment to add the to the xml file
; Syntax: _XMLCreateComment($node,$comment)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) on error set error to 1 and returns -1
;===============================================================================
Func _XMLCreateComment($strNode, $strComment)
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLCreateComment")
Return SetError(1,11,-1)
EndIf
Local $objChild, $objNode
$objNode = $objDoc.selectSingleNode ($strNode)
If IsObj($objNode) Then
If Not ($objNode.hasChildNodes ()) Then
_AddFormat($objDoc, $objNode)
EndIf
$objChild = $objDoc.createComment ($strComment)
$objNode.insertBefore ($objChild, $objNode.childNodes (0))
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
_AddFormat($objDoc)
$objChild = ""
Return 1
EndIf
_XMLError("Failed to root child: " & $strNode & @CRLF)
Return SetError(1,0, -1)
EndFunc ;==>_XMLCreateComment
;===============================================================================
; Function Name: _XMLCreateAttribute
; Description:
; Parameter(s): $strXPath xml tree path from root node (root/child/child..)
; $strAttrName the attribute to set.
; $strAttrValue the value to give the attribute defaults to ""
; Syntax: _XMLCreateAttrib($strXPath,$strAttrName,$strAttrValue="")
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) 1 on success, 0 on error
;===============================================================================
Func _XMLCreateAttrib($strXPath, $strAttrName, $strAttrValue = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLCreateAttrib")
Return SetError(1,12,-1)
EndIf
Local $objNode, $objAttr, $objAttrVal, $err
$objNode = $objDoc.selectSingleNode ($strXPath)
If IsObj($objNode) Then
$objAttr = $objDoc.createAttribute ($strAttrName);, $strNameSpc)
$objNode.SetAttribute ($strAttrName, $strAttrValue)
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
$objAttr = 0
$objAttrVal = 0
$objNode = 0
$err = $objDoc.parseError.errorCode
If $err = 0 Then Return 1
EndIf
_XMLError("Error creating Attribute: " & $strAttrName & @CRLF & $strXPath & " does not exist." & @CRLF)
Return 0
EndFunc ;==>_XMLCreateAttrib
;===============================================================================
; Function Name: _XMLCreateRootChild
; Description: Create node directly under root.
; Parameter(s): $node name of node to create
; $value optional value to create
; Syntax: _XMLCreateRootChild($node,[$value])
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) on error set error to 1 and returns -1
;===============================================================================
Func _XMLCreateRootChild($strNode, $strData = "", $strNameSpc = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLCreateRootChild")
Return SetError(1,14,-1)
EndIf
ConsoleWrite("_XMLCreateRootChild:"&$strNode&@LF)
Local $objChild
If Not ($objDoc.documentElement.hasChildNodes ()) Then
_AddFormat($objDoc)
EndIf
$objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
If IsObj($objChild) Then
If $strData <> "" Then $objChild.text = $strData
$objDoc.documentElement.appendChild ($objChild)
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
_AddFormat($objDoc)
$objChild = 0
Return 1
EndIf
_XMLError("Failed to root child: " & $strNode & @CRLF)
Return SetError(1,0,-1)
EndFunc ;==>_XMLCreateRootChild
;===============================================================================
; Function Name: _XMLCreateRootNodeWAttr
; Description: Create a child node under root node with attributes.
; Parameter(s): $node node to add with attibute(s)
; $[array]attrib attribute name(s) -- can be array
; $[array]value attribute value(s) -- can be array
; $data optional value to give the node.
; Requirements This function requires that each attribute name has
; a corresponding value.
; Syntax: _XMLCreateRootNodeWAttr($node,$array_attribs,$array_value)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) on error set error to 1 or 2 and returns -1
;===============================================================================
Func _XMLCreateRootNodeWAttr($strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLCreateRootNodeWAttr")
Return SetError(1,15,-1)
EndIf
Local $objChild, $objAttr, $objAttrVal
$objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
If IsObj($objChild) Then
If $strData <> "" Then $objChild.text = $strData
If Not ($objDoc.documentElement.hasChildNodes ()) Then
_AddFormat($objDoc)
EndIf
If IsArray($aAttr) And IsArray($aVal) Then
If UBound($aAttr) <> UBound($aVal) Then
_XMLError("Attribute and value mismatch" & @CRLF & "Please make sure each attribute has a matching value.")
SetError(2)
Return -1
Else
Local $i
For $i = 0 To UBound($aAttr) - 1
If $aAttr[$i] = "" Then
_XMLError("Error creating child node: " & $strNode & @CRLF & " Attribute Name Cannot be NULL." & @CRLF)
Return SetError(1,0,-1)
EndIf
$objAttr = $objDoc.createAttribute ($aAttr[$i]);, $strNameSpc)
$objChild.SetAttribute ($aAttr[$i], $aVal[$i])
Next
EndIf
Else
$objAttr = $objDoc.createAttribute ($aAttr)
$objChild.SetAttribute ($aAttr, $aVal)
EndIf
$objDoc.documentElement.appendChild ($objChild)
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
_AddFormat($objDoc)
$objChild = 0
Return 1
EndIf
_XMLError("Failed to create root child with attributes: " & $strNode & @CRLF)
Return SetError(1,0,-1)
EndFunc ;==>_XMLCreateRootNodeWAttr
;===============================================================================
; Function Name: _XMLCreateChildNode
; Description: Create a child node under the specified XPath Node.
; Parameter(s): $path Path from root
; $node Node to add
; Syntax: _XMLCreateChildNode($path,$node)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) on error set error to 1 and returns -1
;===============================================================================
Func _XMLCreateChildNode($strXPath, $strNode, $strData = "", $strNameSpc = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLCreateChildNode")
Return SetError(1,16,-1)
EndIf
Local $objParent, $objChild, $objNodeList
$objNodeList = $objDoc.selectNodes ($strXPath)
If IsObj($objNodeList) And $objNodeList.length > 0 Then
For $objParent In $objNodeList
If Not ($objParent.hasChildNodes ()) Then
_AddFormat($objDoc, $objParent)
EndIf
If $strNameSpc = "" Then
If Not ($objParent.namespaceURI = 0 Or $objParent.namespaceURI = "") Then $strNameSpc = $objParent.namespaceURI
EndIf
;ConsoleWrite("$strNameSpc=" & $strNameSpc & @LF)
$objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
If $strData <> "" Then $objChild.text = $strData
$objParent.appendChild ($objChild)
_AddFormat($objDoc, $objParent)
Next
If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
$objParent = ""
$objChild = ""
Return 1
EndIf
_XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF)
Return SetError(1,0,-1)
EndFunc ;==>_XMLCreateChildNode
;===============================================================================
; Function Name: _XMLCreateChildNodeWAttr
; Description: Create a child node(s) under the specified XPath Node with attributes.
; Parameter(s): $sPath Path from root
; $sNode node to add with attibute(s)
; $[array]attrib attribute name(s) -- can be array
; $[array]value attribute value(s) -- can be array
; $data Optional value to give the child node.
; Requirements This function requires that each attribute name has
; a corresponding value.
; Syntax: _XMLCreateChildNodeWAttr($path,$node,$[array]attrib,$]array]value)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) 0 on error and set error 1 or 2
;===============================================================================
Func _XMLCreateChildNodeWAttr($strXPath, $strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "")
Return _XMLCreateChildWAttr($strXPath, $strNode, $aAttr, $aVal, $strData, $strNameSpc)
EndFunc ;==>_XMLCreateChildNodeWAttr
;===============================================================================
; Function Name: _XMLCreateChildWAttr
; Description: Create a child node(s) under the specified XPath Node with attributes.
; Parameter(s): $sPath Path from root
; $sNode node to add with attibute(s)
; $[array]attrib attribute name(s) -- can be array
; $[array]value attribute value(s) -- can be array
; $data Optional value to give the child node.
; Requirements This function requires that each attribute name has
; a corresponding value.
; Syntax: _XMLCreateChildWAttr($path,$node,$[array]attrib,$]array]value)
; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>
; Return Value(s) 0 on error and set error 1 or 2
;===============================================================================
Func _XMLCreateChildWAttr($strXPath, $strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "")
If not IsObj($objDoc) then
_XMLError("No object passed to function _XMLCreateChildWAttr")
Return SetError(1,18,-1)
EndIf
Local $objParent, $objChild, $objAttr, $objAttrVal, $objNodeList
$objNodeList = $objDoc.selectNodes ($strXPath)
_DebugWrite("Node Selected")
If IsObj($objNodeList) And $objNodeList.length <> 0 Then
_DebugWrite("Entering if")
For $objParent In $objNodeList
If Not ($objParent.hasChildNodes ()) Then
_AddFormat($objDoc, $objParent)
EndIf