forked from chandran-jr/Reubus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_XMLDomWrapper_1.0.3.98_CN.au3
2361 lines (2265 loc) · 95.4 KB
/
_XMLDomWrapper_1.0.3.98_CN.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
;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7
#Tidy_Parameters=/sort_funcs /reel
#include-once
;; 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 arrys instead of objects.
;; TODO: https://msdn.microsoft.com/en-us/library/jj134410(v=vs.85).aspx
; #INDEX# =======================================================================================================================
; Title .........: _XMLDomWrapper
; AutoIt Version : 3.2.3++
; Language ......: English
; Description ...: Functions to use for reading and writing XML using msxml.
; .Initial release Dec. 15, 2005
; .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.
; .Mar 27,2009 Added function to turn off auto indenting, modified _XMLSetAutoSave, add "force" flag to _XMLSaveDoc
; . Replace _XMLTransform with weaponx provided version.
; . Added _XMLSetAutoFormat, _XMLSetAutoSave, _XMLSaveDoc to function list in header.
; .Mar 28,2009 Changed and verified (hopefuly) all function headers to be inline with current standard.
; . Verifed return values make documentation.
; . Automatic saving is now off by default.
; . Automatic formatting is now off by default.
; .Mar 30,2009 Fixed a bug in _XMLGetChildren where passing the root would get values of grandchildren.
; .Apr 24,2009 Reverted Autosave and Autoformat.
; . Fixed doc error regrading Autoindent vs Autoformat.
; . Change boolean vars to start with $f instead of $b
; .Apr 25,2009 Experimental code to remove indenting text node when a node is deleted.
; .Apr 27,2010 added _XMLUpdateField2 per weaponx. Should update multiple nodes.
; .Aug 12,2010 Added remarks to _XMLCreateFile.
; Added func _XMLGetParent -- Thanks Mike Rerick
; Author ........: Stephen Podhajecki Eltorro, Weaponx
; ===============================================================================================================================
; XML DOM Wrapper functions
#cs defs to add to au3.api
_XMLCreateFile($sPath, $sRootNode, [$fOverwrite = False]) Creates an XML file with the given name and root.
_XMLFileOpen($sXMLFile,[$sNamespace=""],[$ver=-1]) Creates an instance of an XML file.
_XMLSaveDoc( $sFile="",$iForce = 0 ) Save the xml doc, use $iForce = 1 to force save if AutoSave is off.
; =============================================================================
_XMLGetChildNodes ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node.
_XMLGetNodeCount ( strXPath, strQry = "", iNodeType = 1 ) Get node count for specified path and type.
_XMLGetPath ( strXPath ) Returns a nodes full path based on XPath input from root node.
_XMLGetParent($strXPath) Gets the parent node name of the node pointed to by the XPath.
; =============================================================================
_XMLSelectNodes ( strXPath ) Selects XML Node(s) based on XPath input from root node.
_XMLGetField ( strXPath ) Get XML Field(s) based on XPath input from root node.
_XMLGetValue ( strXPath ) Get XML Field based on XPath input from root node.
_XMLGetChildText ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node.
_XMLUpdateField ( strXPath, strData ) Update existing node based on XPath specs.
_XMLUpdateField2 ( strXPath, strData ) Update existing node(s) based on XPath specs.
_XMLReplaceChild ( objOldNode, objNewNode, ns = "" ) Replaces a node with a new node.
; =============================================================================
_XMLDeleteNode ( strXPath ) Delete specified XPath node.
_XMLDeleteAttr ( strXPath, strAttrib ) Delete attribute for specified XPath
_XMLDeleteAttrNode ( strXPath, strAttrib ) Delete attribute node for specified XPath
; =============================================================================
_XMLGetAttrib ( strXPath, strAttrib, strQuery = "" ) Get XML attribute based on XPath input from root node.
_XMLGetAllAttrib ( strXPath, ByRef aName, ByRef aValue, strQry = "" ) Get all XML Field(s) attributes based on XPath input from root node.
_XMLGetAllAttribIndex ( strXPath, ByRef aName, ByRef aValue, strQry = "", NodeIndex = 0 ) Get all XML Field(s) attributes based on Xpathn and specific index.
_XMLSetAttrib ( strXPath, strAttrib, strValue = "" ) Set XML Field(s) attributes based on XPath input from root node.
; =============================================================================
_XMLCreateCDATA ( strNode, strCDATA, strNameSpc = "" ) Create a CDATA SECTION node directly under root.
_XMLCreateComment ( strNode, strComment ) Create a COMMENT node at specified path.
_XMLCreateAttrib ( strXPath,strAttrName,strAttrValue="" ) Creates an attribute for the specified node.
; =============================================================================
_XMLCreateRootChild ( strNode, strData = "", strNameSpc = "" ) Create node directly under root.
_XMLCreateRootNodeWAttr ( strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under root node with attributes.
_XMLCreateChildNode ( strXPath, strNode, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node.
_XMLCreateChildWAttr ( strXPath, strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node with Attributes.
; =============================================================================
_XMLSchemaValidate ( sXMLFile, ns, sXSDFile ) _XMLSchemaValidate($sXMLFile, $ns, $sXSDFile) Validate a document against a DTD.
_XMLGetDomVersion ( ) Returns the XSXML version currently in use.
_XMLError ( sError = "" ) Sets or Gets XML error message generated by XML functions.
_XMLUDFVersion ( ) Returns the UDF Version number.
_XMLTransform ( oXMLDoc, Style = "",szNewDoc="" ) Transfroms the document using built-in sheet or xsl file passed to function.
_XMLNodeExists( $strXPath) Checks for the existence of the specified path.
; =============================================================================
_XMLSetAutoFormat( $fAutoFormat = True ) Turn auto indenting on or off.
_XMLSetAutoSave( $fSave = True ) Set the automatic save to on or off.
#ce
; #VARIABLES# ===================================================================================================================
Global Const $_XMLUDFVER = "1.0.3.98"
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 $oXMLMyError ;COM error handler OBJ ; Initialize SvenP 's error handler
Global $sXML_error
Global $fDEBUGGING
Global $DOMVERSION = -1
Global $objDoc
Global $fXMLAUTOSAVE = True ;auto save updates
Global $fADDFORMATTING = True ;auto indent
; #INTERNAL_USE_ONLY#==========================================================
; Name ..........: _AddFormat
; Description ...:
; Syntax.........: _AddFormat($objDoc[, $objParent = ""])
; Parameters ....: $objDoc - Document to format
; $objParent - Optional node to add formatting to
; Return values .: Success - 1
; Failure - -1 and @error set to 1.
; Author ........: Stephen Podhajecki <gehossafats a t netmdc.com>
; Modified ......:
; Remarks .......: Just break up the tags, no indenting is done here.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _AddFormat($objDoc, $objParent = "")
If $fADDFORMATTING = True Then
If Not IsObj($objDoc) Then
_XMLError("No object passed to function _XMLAddFormat")
Return SetError(1, 30, -1)
EndIf
Local $objFormat = $objDoc.createTextNode(@CR)
If IsObj($objParent) Then
$objParent.appendChild($objFormat)
Else
$objDoc.documentElement.appendChild($objFormat)
EndIf
_XMLSaveDoc($strFile)
EndIf
Return 1
EndFunc ;==>_AddFormat
; #FUNCTION# ===================================================================
; Name ..........: _ComErrorHandler
; Description ...: A COM error handling routine.
; Syntax.........: _ComErrorHandler($quiet = "")
; Parameters ....: $quiet - Work silently
; Return values .: None
; Author ........:
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _ComErrorHandler($quiet = "")
Local $COMErr_Silent, $HexNumber
; ==============================================================================
; added silent switch to allow the func returned to the option to display custom
; error messages
If $quiet = True Or $quiet = False Then
$COMErr_Silent = $quiet
$quiet = ""
EndIf
; ==============================================================================
$HexNumber = Hex($oXMLMyError.number, 8)
If @error Then Return
Local $msg = "COM Error with DOM!" & @CRLF & @CRLF & _
"err.description is: " & @TAB & $oXMLMyError.description & @CRLF & _
"err.windescription:" & @TAB & $oXMLMyError.windescription & @CRLF & _
"err.number is: " & @TAB & $HexNumber & @CRLF & _
"err.lastdllerror is: " & @TAB & $oXMLMyError.lastdllerror & @CRLF & _
"err.scriptline is: " & @TAB & $oXMLMyError.scriptline & @CRLF & _
"err.source is: " & @TAB & $oXMLMyError.source & @CRLF & _
"err.helpfile is: " & @TAB & $oXMLMyError.helpfile & @CRLF & _
"err.helpcontext is: " & @TAB & $oXMLMyError.helpcontext
If $COMErr_Silent <> True Then
MsgBox(0, @AutoItExe, $msg)
Else
_XMLError($msg)
EndIf
SetError(1)
EndFunc ;==>_ComErrorHandler
; simple helper functions
; #FUNCTION# ===================================================================
; Name ..........: _DebugWrite
; Description ...: Writes a message to console with a crlf on the end
; Syntax.........: _DebugWrite($strMsg[, $sLineEnding = @LF])
; Parameters ....: $strMsg - The message to display
; $sLineEnding - Line ending to add
; Return values .: On Succes - None.
; Failure - None.
; Author ........:
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _DebugWrite($strMsg, $sLineEnding = @LF)
If $fDEBUGGING Then
ConsoleWrite(StringFormat($strMsg) & $sLineEnding)
EndIf
EndFunc ;==>_DebugWrite
; #INTERNAL_USE_ONLY#==========================================================
; Name ..........: _GetDefaultStyleSheet
; Description ...: Internal function, returns the default indenting style sheet.
; Syntax.........: _GetDefaultStyleSheet()
; Parameters ....:
; Return values .: Success - The default stylesheet.
; Failure - Nothing.
; Author ........: Hew Wolff - Art & Logic, Inc.
; Modified ......:
; Remarks .......: Posted all over the web.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _GetDefaultStyleSheet()
Return '<?xml version="1.0" encoding="UTF-8"?>' & _
'<!--' & _
'Converts XML into a nice readable format.' & _
'Tested with Saxon 6.5.3.' & _
'As a test, this stylesheet should not change when run on itself.' & _
'But note that there are no guarantees about attribute order within an' & _
'element (see http://www.w3.org/TR/xpath#dt-document-order), or about' & _
'which characters are escaped (see' & _
'http://www.w3.org/TR/xslt#disable-output-escaping).' & _
'I did not test processing instructions, CDATA sections, or' & _
'namespaces.' & _
'Hew Wolff' & _
'Senior Engineer' & _
'Art & Logic, Inc.' & _
'www.artlogic.com' & _
'-->' & _
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">' & _
'<!-- Take control of the whitespace. -->' & _
'<xsl:output method="xml" indent="no" encoding="UTF-8"/>' & _
'<xsl:strip-space elements="*"/>' & _
'<xsl:preserve-space elements="xsl:text"/>' & _
'<!-- Copy comments, and elements recursively. -->' & _
'<xsl:template match="*|comment()">' & _
'<xsl:param name="depth">0</xsl:param>' & _
'<!--' & _
'Set off from the element above if one of the two has children.' & _
'Also, set off a comment from an element.' & _
'And set off from the XML declaration if necessary.' & _
'-->' & _
'<xsl:variable name="isFirstNode" select="count(../..) = 0 and position() = 1"/>' & _
'<xsl:variable name="previous" select="preceding-sibling::node()[1]"/>' & _
'<xsl:variable name="adjacentComplexElement" select="count($previous/*) > 0 or count(*) > 0"/>' & _
'<xsl:variable name="adjacentDifferentType" select="not(($previous/self::comment() and self::comment()) or ($previous/self::* and self::*))"/>' & _
'<xsl:if test="$isFirstNode or ($previous and ($adjacentComplexElement or $adjacentDifferentType))">' & _
'<xsl:text>
</xsl:text>' & _
'</xsl:if>' & _
'<!-- Start a new line.' & _
'<xsl:text>
</xsl:text> -->' & _
'<xsl:call-template name="indent">' & _
'<xsl:with-param name="depth" select="$depth"/>' & _
'</xsl:call-template>' & _
'<xsl:copy>' & _
'<xsl:if test="self::*">' & _
'<xsl:copy-of select="@*"/>' & _
'<xsl:apply-templates>' & _
'<xsl:with-param name="depth" select="$depth + 1"/>' & _
'</xsl:apply-templates>' & _
'<xsl:if test="count(*) > 0">' & _
'<xsl:text>
</xsl:text>' & _
'<xsl:call-template name="indent">' & _
'<xsl:with-param name="depth" select="$depth"/>' & _
'</xsl:call-template>' & _
'</xsl:if>' & _
'</xsl:if>' & _
'</xsl:copy>' & _
'<xsl:variable name="isLastNode" select="count(../..) = 0 and position() = last()"/>' & _
'<xsl:if test="$isLastNode">' & _
'<xsl:text>
</xsl:text>' & _
'</xsl:if>' & _
'</xsl:template>' & _
'<xsl:template name="indent">' & _
'<xsl:param name="depth"/>' & _
'<xsl:if test="$depth > 0">' & _
'<xsl:text> </xsl:text>' & _
'<xsl:call-template name="indent">' & _
'<xsl:with-param name="depth" select="$depth - 1"/>' & _
'</xsl:call-template>' & _
'</xsl:if>' & _
'</xsl:template>' & _
'<!-- Escape newlines within text nodes, for readability. -->' & _
'<xsl:template match="text()">' & _
'<xsl:call-template name="escapeNewlines">' & _
'<xsl:with-param name="text">' & _
'<xsl:value-of select="."/>' & _
'</xsl:with-param>' & _
'</xsl:call-template>' & _
'</xsl:template>' & _
'<xsl:template name="escapeNewlines">' & _
'<xsl:param name="text"/>' & _
'<xsl:if test="string-length($text) > 0">' & _
'<xsl:choose>' & _
'<xsl:when test="substring($text, 1, 1) = ' & "'#xA;'" & '">' & _
'<xsl:text disable-output-escaping="yes">&#xA;</xsl:text>' & _
'</xsl:when>' & _
'<xsl:otherwise>' & _
'<xsl:value-of select="substring($text, 1, 1)"/>' & _
'</xsl:otherwise>' & _
'</xsl:choose>' & _
'<xsl:call-template name="escapeNewlines">' & _
'<xsl:with-param name="text" select="substring($text, 2)"/>' & _
'</xsl:call-template>' & _
'</xsl:if>' & _
'</xsl:template>' & _
'</xsl:stylesheet>'
EndFunc ;==>_GetDefaultStyleSheet
; #FUNCTION# ===================================================================
; Name ..........: _Notifier
; Description ...: displays a simple "ok" messagebox
; Syntax.........: _Notifier($Notifier_msg)
; Parameters ....: $Notifier_Msg - The message to display
; Return values .: On Succes - None.
; Failure - None.
; Author ........:
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _Notifier($Notifier_msg)
MsgBox(266288, @ScriptName, $Notifier_msg)
EndFunc ;==>_Notifier
; #FUNCTION# ===================================================================
; Name ..........: _SetDebug
; Description ...: Turn debugging info on or off
; Syntax.........: _SetDebug($fDbug = True)
; Parameters ....: $fDbug - Boolean value for debugging.
; Return values .: Success - The debugging state.
; Author ........:
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _SetDebug($fDbug = True)
$fDEBUGGING = $fDbug
_DebugWrite("Debug = " & $fDEBUGGING)
Return $fDEBUGGING
EndFunc ;==>_SetDebug
; #INTERNAL_USE_ONLY#==========================================================
; Name ..........: _XMLArrayAdd
; Description ...: Adds an item to an array.
; Syntax.........: _XMLArrayAdd(ByRef $avArray, $sValue)
; Parameters ....: $avArray - The array to modify.
; $sValue - The value to add to the array.
; Return values .: Success - 1 and value added to array.
; Failure - 0 and @error set to 1
; Author ........:
; Modified ......:
; Remarks .......: Local version of _ArrayAdd to remove dependency on Array.au3
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLArrayAdd(ByRef $avArray, $sValue)
If IsArray($avArray) Then
ReDim $avArray[UBound($avArray) + 1]
$avArray[UBound($avArray) - 1] = $sValue
SetError(0)
Return 1
Else
SetError(1)
Return 0
EndIf
EndFunc ;==>_XMLArrayAdd
; From the forum this came.
; #FUNCTION# ===================================================================
; Name ..........: _XMLCOMEerr
; Description ...: Displays a message box with the COM Error.
; Syntax.........: _XMLCOMEerr()
; Parameters ....: None
; Return values .:
; Author ........: SvenP 's error handler
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCOMEerr()
_ComErrorHandler()
Return
EndFunc ;==>_XMLCOMEerr
; #FUNCTION# ===================================================================
; Name ..........: _XMLCreateAttribute
; Description ...: Adds an XML Attribute to specified node.
; Syntax.........: _XMLCreateAttrib($strXPath, $strAttrName[, $strAttrValue = ""])
; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..)
; $strAttrName - The attribute to set.
; $strAttrValue - The value to give the attribute, defaults to "".
; Return values .: Success - 1
; Failure - 0 or @error set to 0 and return -1
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateAttrib(ByRef $objDoc, $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)
_XMLSaveDoc($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 ..........: _XMLCreateCDATA
; Description ...: Create a CDATA SECTION node directly under root.
; Syntax.........: _XMLCreateCDATA($strNode, $strCDATA[, $strNameSpc = ""])
; Parameters ....: $strNode - name of node to create
; $strData - CDATA value
; $strNameSpc - the namespace to specifiy if the xml uses one.
; Return values .: Success - 1
; Failure - 1 and sets @Error to 1.
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......: fixme, won't append to exisiting node. must create new node.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateCDATA(ByRef $objDoc, $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)
_XMLSaveDoc($strFile)
_AddFormat($objDoc)
$objChild = ""
Return 1
EndIf
_XMLError("Failed to create CDATA Section: " & $strNode & @CRLF)
Return SetError(1, 0, -1)
EndFunc ;==>_XMLCreateCDATA
; #FUNCTION# ===================================================================
; Name ..........: _XMLCreateChildNode
; Description ...: Create a child node under the specified XPath Node.
; Syntax.........: _XMLCreateChildNode($strXPath, $strNode[, $strData = ""[, $strNameSpc = ""]])
; Parameters ....: $strXPath - The node from root.
; $strNode - Node name to add.
; $strData - Value to give the node
; Return values .: Success - 1
; Failure - -1 and @error set to 1.
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateChildNode(ByRef $objDoc, $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
_XMLSaveDoc($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.
; Syntax.........: _XMLCreateChildNodeWAttr($strXPath, $strNode, $aAttr, $aVal[, $strData = ""[, $strNameSpc = ""]])
; Parameters ....: $sPath - Path from root
; $sNode - node to add with attibute(s)
; $aAttr - The attribute name(s) -- can be array
; $aVal - The attribute value(s) -- can be array
; $strData - The optional value to give the child node.
; Return values .: Success - 1
; Failure - -1, @error set to:
; |1 - Could not create node.
; |2 - Mismatch between attribute name and value counts.
; |3 - Attribute Name cannot be empty string.
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......: This function requires that each attribute name has a corresponding value.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateChildNodeWAttr(ByRef $objDoc, $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.
; Syntax.........: _XMLCreateChildWAttr($strXPath, $strNode, $aAttr, $aVal[, $strData = ""[, $strNameSpc = ""]])
; Parameters ....: $sPath - Path from root
; $sNode - The node to add with attibute(s)
; $aAttr - The attribute name(s) -- can be array
; $aVal - The attribute value(s) -- can be array
; $strData - The optional value to give the child node.
; Return values .: Success - 1
; Failure - -1, @error set to:
; |1 - Could not create node.
; |2 - Mismatch between attribute name and value counts.
; |3 - Attribute Name cannot be empty string.
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......: This function requires that each attribute name has a corresponding value.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateChildWAttr(ByRef $objDoc, $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
_DebugWrite("Entering for")
If $strNameSpc = "" Then
If Not ($objParent.namespaceURI = 0 Or $objParent.namespaceURI = "") Then $strNameSpc = $objParent.namespaceURI
EndIf
$objChild = $objDoc.createNode($NODE_ELEMENT, $strNode, $strNameSpc)
If @error Then Return -1
If $strData <> "" Then $objChild.text = $strData
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.")
Return SetError(2, 0, -1)
Else
Local $i
For $i = 0 To UBound($aAttr) - 1
_DebugWrite("Entering inside for")
If $aAttr[$i] = "" Then
_XMLError("Error creating child node: " & $strNode & @CRLF & " Attribute Name Cannot be NULL." & @CRLF)
Return SetError(1, 0, -1)
EndIf
_DebugWrite($aAttr[$i] & " " & $strNameSpc)
$objAttr = $objDoc.createAttribute($aAttr[$i]);, $strNameSpc)
If @error Then ExitLoop
$objChild.SetAttribute($aAttr[$i], $aVal[$i])
If @error <> 0 Then
_XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF)
Return SetError(1, 0, -1)
EndIf
_DebugWrite("Looping inside for")
Next
EndIf
Else
If IsArray($aAttr) Or IsArray($aVal) Then
_XMLError("Type non-Array and Array detected" & @LF)
Return SetError(1, 0, -1)
EndIf
If $aAttr = "" Then
_XMLError("Attribute Name cannot be empty string." & @LF)
Return SetError(3, 0, -1)
EndIf
_DebugWrite($aAttr & " " & $strNameSpc)
$objAttr = $objDoc.createAttribute($aAttr);, $strNameSpc)
$objChild.SetAttribute($aAttr, $aVal)
EndIf
$objParent.appendChild($objChild)
_DebugWrite("Looping for")
Next
_AddFormat($objDoc, $objParent)
_XMLSaveDoc($strFile)
_DebugWrite("Saved")
$objParent = ""
$objChild = ""
_DebugWrite("Returning")
Return 1
EndIf
_XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF)
Return SetError(1, 0, -1)
EndFunc ;==>_XMLCreateChildWAttr
; #FUNCTION# ===================================================================
; Name ..........: _XMLCreateComment
; Description ...: Create a COMMENT node at specified path.
; Syntax.........: _XMLCreateComment($strNode, $strComment)
; Parameters ....: $strNode - The name of node to create.
; $strComment - The comment to add the to the xml file.
; Return values .: Success - 1
; Failure - -1 and @error set to 1.
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateComment(ByRef $objDoc, $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))
_XMLSaveDoc($strFile)
_AddFormat($objDoc)
$objChild = ""
Return 1
EndIf
_XMLError("Failed to root child: " & $strNode & @CRLF)
Return SetError(1, 0, -1)
EndFunc ;==>_XMLCreateComment
; #FUNCTION# ===================================================================
; Name ..........: _XMLCreateFile
; Description ...: Create a new blank metafile with header.
; Syntax.........: _XMLCreateFile($strPath, $strRoot[, $fOverwrite = False[, $fUTF8 = False[, $ver = -1]]])
; Parameters ....: $strPath - The xml filename with full path to create
; $strRoot - The root of the xml file to create
; $fOverwrite - boolean flag to auto overwrite existing file of same name.
; $fUTF8 - boolean flag to specify UTF-8 encoding in header.
; $iVer - specifically try to use the version supplied here.
; Return values .: Success - 1
; 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 ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......: Use _XMLFileOpen after using this function to access the file. (PsaltyDS)
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateFile($strPath, $strRoot, $fOverwrite = False, $fUTF8 = False, $ver = -1)
Local $retval, $fe, $objPI, $rootElement
$fe = FileExists($strPath)
If $fe And Not $fOverwrite 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 $fUTF8 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)
; _XMLSaveDoc (,1)
If $objDoc.parseError.errorCode <> 0 Then
_XMLError("Error Creating specified file: " & $strPath)
; Tom Hohmann 2008/02/29
$objDoc = 0
SetError(1, $objDoc.parseError.errorCode, -1)
Return -1
EndIf
Return 1
Else
_XMLError("Error! Failed to create file: " & $strPath)
$objDoc = 0
SetError(1)
Return 0
EndIf
$objDoc = 0
Return 1
EndFunc ;==>_XMLCreateFile
; #FUNCTION# ===================================================================
; Name ..........: _XMLCreateRootChild
; Description ...: Create node directly under root.
; Syntax.........: _XMLCreateRootChild($strNode[, $strData = ""[, $strNameSpc = ""]])
; Parameters ....: $strNode - The name of node to create.
; $strData - The optional value to create
; $$strNameSpc - the namespace to specifiy if the file uses one.
; Return values .: Success - 1
; Failure - -1 and @error set to 1.
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateRootChild(ByRef $objDoc, $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)
_XMLSaveDoc($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.
; Syntax.........: _XMLCreateRootNodeWAttr($strNode, $aAttr, $aVal[, $strData = ""[, $strNameSpc = ""]])
; Parameters ....: $strNode - The node to add with attibute(s)
; $aAttr - The attribute name(s) -- can be array
; $aVal - The attribute value(s) -- can be array
; $strData - The optional value to give the node.
; Return values .: Success - 1
; Failure - -1 and @error set to:
; |1 - Could not create node.
; |2 - Mismatch between attribute name and value counts.
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......: This function requires that each attribute name has a corresponding value.
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLCreateRootNodeWAttr(ByRef $objDoc, $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.")
Return SetError(2, 15, -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)
_XMLSaveDoc($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 ..........: _XMLDeleteAttr
; Description ...: Delete XML Attribute based on XPath input from root node.
; Syntax.........: _XMLDeleteAttr($strXPath, $strAttrib)
; Parameters ....: $strXPath - The XML tree path from root node (root/child/child..)
; $strAttribute - The attribute node to delete
; Return values .: Success - 1
; Failure - -1 and sets @Error to:
; |0 - No error
; |1 - Error removing attribute
; |2 - No object
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLDeleteAttr(ByRef $objDoc, $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)
_XMLSaveDoc($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.
; Syntax.........: _XMLDeleteAttrNode($strXPath, $strAttrib)
; Parameters ....: $strXpath - XML tree path from root node (root/child/child..)
; $strAttrib - The attribute node to delete
; Return values .: Success - 1
; Failure - -1 and sets @Error to:
; |0 - No error
; |1 - Error removing node
; |2 - No object
; Author ........: Stephen Podhajecki <gehossafats@netmdc.com>
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; [yes/no]
; ==============================================================================
Func _XMLDeleteAttrNode(ByRef $objDoc, $strXPath, $strAttrib)
If Not IsObj($objDoc) Then
_XMLError("No object passed to function _XMLDeleteAttrNode")
Return SetError(2, 0, -1)
EndIf
Local $objNode, $objAttr
; Local $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))
_XMLSaveDoc($strFile)
If Not (IsObj($objAttr)) Then
_XMLError("\nUnspecified error:!")
Return SetError(1, 0, -1)
EndIf
Return 1
EndFunc ;==>_XMLDeleteAttrNode