Guest User

Untitled

a guest
Jan 13th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 74.72 KB | None | 0 0
  1. #include-once
  2. ; =======================================================================
  3. ; Project Manager 3.0 Preprocessed - Date 25:04:2007 Time 14:28
  4. ; =======================================================================
  5. ; ------------------------------------------------------------------------------
  6. ;
  7. ; AutoIt Version:   3.0
  8. ; Language:         English
  9. ; Description:      Functions that assist with using xml files
  10. ;                   Stephen Podhajecki <[email protected]>
  11. ; Dec 15, 2005, Update Jan10,2006, Update Feb 5,8,14-15, 2006
  12. ; Feb 24, 2006 Updated _XMLCreateCDATA, code cleaned up Gary Frost ([email protected])
  13. ; Feb 24, 2006 bug fix in re-init COM error handler, rewrote _XMLCreateChildNodeWAttr()
  14. ; Jun 20, 2006 Added count to index[0] of the _XMLGetValue return value
  15. ; Jun 26, 2006 Changed _XMLCreateFile to include option flag for UTF-8 encoding
  16. ; Jun 29, 2006 Added count to index[0] of the _XMLGetValue return
  17. ;                   Changed _XMLFileOpen and _XMLFileCreate
  18. ; Mar 30, 2007 Rewrote _AddFormat function to break up tags( no indentation)
  19. ;                   Added _XMLTransform() which runs the document against a xsl(t) style sheet for indentation.
  20. ;                   Changed _XMLCreateRootChildWAttr() to use new formatting
  21. ;                   Changed _XMLChreateChildNode() to use new formatting
  22. ; Apr 02, 2007 Added _XMLReplaceChild()
  23. ; Apr 03, 2007 Changed other node creating function to use new formatting
  24. ;                   Changed _XMLFileOpen() _XMLFileCreate to take an optional version number of MSXML to use.
  25. ;                   Changed _XMLFileOpen() _XMLFileCreate find latest MSXML version logic.
  26. ; Apr 24, 2007 Fixed _XMLCreateChileNodeWAttr() - Instead of removal, It points to the function that replaced it.
  27. ; Apr 25, 2007 Added _XMLCreateAttrib()
  28. ;                   Fixed bug with _XMLCreateRootNodeWAttr , _XMLCreateChild[Node]WAttr() where an extra node with same name was added.
  29. ;                   Stripped extrenous comments.
  30. ;                   Removed dependency on Array.au3 (I added the func from Array.au3 and renamed it to avoid conflicts.)
  31. ; May 03, 2007  Changed method of msxml version lookup.  Updated api call tips.
  32. ; May 11, 2007 Fixed missing \
  33. ; Jun 08, 2007 Fixed Namespace issue with _XMLCreateChildNode() and _XMLCreateChildNodeWAttr()
  34. ; Jun 12, 2007 Added workaround for MSXML6 to parse file with DTD's
  35. ; Jun 13, 2007 Fixed bug in _XMLGetField() where all text was returned in one node.
  36. ;                       Actually this is not a bug, because it is the way that WC3 says it will be returned
  37. ;                       However, it will now return in a way that is expected.
  38. ;                   _XMLGetValue now returns just the text associated with the node or empty string.
  39. ; Jul 20, 2007 Fixed bug where failure to open the xml file would return an empty xml object, it now returns 0(no object).
  40. ;                   Added object check to all applicable functions.
  41. ; Aug 08, 2007 Add a _XMLSetAutoSave() to turn off/on forced saving within each function. --Thanks drlava
  42. ;                   Added check for previous COM error handler.     --Thanks Lukasz Suleja
  43. ; Aug 27,2007  Changed property setting order for _XMLFileOpen.  The previous order was causing a problem with default namespaces.
  44. ;                   -- It seems that "selectionLanguage" needs to be declared before some other properties.
  45. ; Aug 31,2007 Fixed bug where _XMLUpdateField would inadvertantly erase child nodes.
  46. ; Sep 07,2007 Fixed _XMLDeleteNode bug where non-existant node cause COM error.
  47. ;                 Added _XMLNodeExist function to check for the existence of node or nodes matching the specified path
  48. ; Jan 05,2008 Fixed documentation problem in function header with _XMLGetAttrib.
  49. ; Feb 25,2008 Fixed dimensioning bug in _XMLGetChildren  --Thanks oblique
  50. ; Mar 05,2008 Return values fixed for the following functions: --Thanks oblique
  51. ;             _XMLFileOpen ,_XMLLoadXML,_XMLCreateFile,
  52. ;             Documentation fixed for _XMLGetNodeCount,_XMLGetChildren --Thanks oblique
  53. ; Mar 07,2008 Small changes.
  54. ;             Fixed an issue point out by lgr.
  55. ; ------------------------------------------------------------------------------
  56. ;===============================================================================
  57. ; XML DOM Wrapper functions
  58. ;
  59. ; These funtions require BETA as they need support for COM
  60. ;
  61. ;===============================================================================
  62. #cs defs to add to au3.api
  63.     _XMLCreateFile($sPath, $sRootNode, [$bOverwrite = False]) Creates an XML file with the given name and root.(Requires: #include <_XMLDomWrapper.au3>)
  64.     _XMLFileOpen($sXMLFile,[$sNamespace=""],[$ver=-1]) Creates an instance of an XML file.(Requires: #include <_XMLDomWrapper.au3>)
  65.     ;==============================================================================
  66.     _XMLGetChildNodes ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
  67.     _XMLGetNodeCount ( strXPath, strQry = "", iNodeType = 1 ) Get node count for specified path and type. (Requires: #include <_XMLDomWrapper.au3>)
  68.     _XMLGetPath ( strXPath ) Returns a nodes full path based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
  69.     ;==============================================================================
  70.     _XMLSelectNodes ( strXPath ) Selects XML Node(s) based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
  71.     _XMLGetField ( strXPath ) Get XML Field(s) based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
  72.     _XMLGetValue ( strXPath ) Get XML Field based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
  73.     _XMLGetChildText ( strXPath ) Selects XML child Node(s) of an element based on XPath input from root node. (Requires: #include <_XMLDomWrapper.au3>)
  74.     _XMLUpdateField ( strXPath, strData ) Update existing node(s) based on XPath specs.(Requires: #include <_XMLDomWrapper.au3>)
  75.     _XMLReplaceChild ( objOldNode, objNewNode, ns = "" ) Replaces a node with a new node. (Requires: #include <_XMLDomWrapper.au3>)
  76.     ;==============================================================================
  77.     _XMLDeleteNode ( strXPath ) Delete specified XPath node.(Requires: #include <_XMLDomWrapper.au3>)
  78.     _XMLDeleteAttr ( strXPath, strAttrib ) Delete attribute for specified XPath(Requires: #include <_XMLDomWrapper.au3>)
  79.     _XMLDeleteAttrNode ( strXPath, strAttrib ) Delete attribute node for specified XPath(Requires: #include <_XMLDomWrapper.au3>)
  80.     ;==============================================================================
  81.     _XMLGetAttrib ( strXPath, strAttrib, strQuery = "" ) Get XML attribute based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
  82.     _XMLGetAllAttrib ( strXPath, ByRef aName, ByRef aValue, strQry = "" ) Get all XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
  83.     _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>)
  84.     _XMLSetAttrib ( strXPath, strAttrib, strValue = "" ) Set XML Field(s) attributes based on XPath input from root node.(Requires: #include <_XMLDomWrapper.au3>)
  85.     ;==============================================================================
  86.     _XMLCreateCDATA ( strNode, strCDATA, strNameSpc = "" ) Create a CDATA SECTION node directly under root. (Requires: #include <_XMLDomWrapper.au3>)
  87.     _XMLCreateComment ( strNode, strComment ) Create a COMMENT node at specified path.(Requires: #include <_XMLDomWrapper.au3>)
  88.     _XMLCreateAttrib ( strXPath,strAttrName,strAttrValue="" ) Creates an attribute for the specified node. (Requires: #include <_XMLDomWrapper.au3>)
  89.     ;==============================================================================
  90.     _XMLCreateRootChild ( strNode, strData = "", strNameSpc = "" ) Create node directly under root.(Requires: #include <_XMLDomWrapper.au3>)
  91.     _XMLCreateRootNodeWAttr ( strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under root node with attributes.(Requires: #include <_XMLDomWrapper.au3>)
  92.     _XMLCreateChildNode ( strXPath, strNode, strData = "", strNameSpc = "" )  Create a child node under the specified XPath Node.(Requires: #include <_XMLDomWrapper.au3>)
  93.     _XMLCreateChildWAttr ( strXPath, strNode, aAttr, aVal, strData = "", strNameSpc = "" ) Create a child node under the specified XPath Node with Attributes. (Requires: #include <_XMLDomWrapper.au3>)
  94.     ;==============================================================================
  95.     _XMLSchemaValidate ( sXMLFile, ns, sXSDFile )   _XMLSchemaValidate($sXMLFile, $ns, $sXSDFile) Validate a document against a DTD. (Requires: #include <_XMLDomWrapper.au3>)
  96.     _XMLGetDomVersion (  ) Returns the XSXML version currently in use. (Requires: #include <_XMLDomWrapper.au3>)
  97.     _XMLError ( sError = "" ) Sets or Gets XML error message generated by XML functions.(Requires: #include <_XMLDomWrapper.au3>)
  98.     _XMLUDFVersion (  ) eturns the UDF Version number. (Requires: #include <_XMLDomWrapper.au3>)
  99.     _XMLTransform ( oXMLDoc, Style = "",szNewDoc="" ) Transfroms the document using built-in sheet or xsl file passed to function. (Requires: #include <_XMLDomWrapper.au3>)
  100.     _XMLNodeExists( $strXPath) Checks for the existence of the specified path. (Requires: #include <_XMLDomWrapper.au3>)
  101. #ce
  102. ;===============================================================================
  103. ;Global variables
  104. Global Const $_XMLUDFVER = "1.0.3.87"
  105. Global Const $NODE_ELEMENT = 1
  106. Global Const $NODE_ATTRIBUTE = 2
  107. Global Const $NODE_TEXT = 3
  108. Global Const $NODE_CDATA_SECTION = 4
  109. Global Const $NODE_ENTITY_REFERENCE = 5
  110. Global Const $NODE_ENTITY = 6
  111. Global Const $NODE_PROCESSING_INSTRUCTION = 7
  112. Global Const $NODE_COMMENT = 8
  113. Global Const $NODE_DOCUMENT = 9
  114. Global Const $NODE_DOCUMENT_TYPE = 10
  115. Global Const $NODE_DOCUMENT_FRAGMENT = 11
  116. Global Const $NODE_NOTATION = 12
  117. Global $strFile
  118. Global $objDoc
  119. Global $oXMLMyError ;COM error handler OBJ ; Initialize SvenP 's error handler
  120. Global $sXML_error
  121. Global $debugging
  122. Global $DOMVERSION = -1
  123. Global $bXMLAUTOSAVE = True
  124. ;===============================================================================
  125. ;UDF functions
  126. ;===============================================================================
  127. ; Function Name:     _XMLFileOpen
  128. ; Description:      Creates an instance of an XML file.
  129. ; Parameter(s): $strXMLFile - the XML file to open
  130. ;                       $strNameSpc - the namespace to specifiy if the file uses one.
  131. ;                       $iVer - specifically try to use the version supplied here.
  132. ;                       $bValOnParse - validate the document as it is being parsed
  133. ; Syntax:            _XMLFileOpen($strXMLFile, [$strNameSpc], [$iVer], [$bValOnParse] )
  134. ; Return Value(s): On Success - 1
  135. ;                        On Failure - -1 and set
  136. ;                           @Error to:
  137. ;                               0 - No error
  138. ;                               1 - Parse error, @Extended = MSXML reason
  139. ;                               2 - No object
  140. ; Author(s):        Stephen Podhajecki <[email protected]>
  141. ;===============================================================================
  142. Func _XMLFileOpen($strXMLFile, $strNameSpc = "", $iVer = -1, $bValOnParse = True)
  143.     ;==== pick your poison
  144.     If $iVer <> -1 Then
  145.         If $iVer > -1 And $iVer < 7 Then
  146.             $objDoc = ObjCreate("Msxml2.DOMDocument." & $iVer & ".0")
  147.             If IsObj($objDoc) Then
  148.                 $DOMVERSION = $iVer
  149.             EndIf
  150.         Else
  151.             MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $iVer)
  152.             SetError(1)
  153.             Return 0
  154.         EndIf
  155.     Else
  156.         For $x = 8 To 0 Step - 1
  157.             If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then
  158.                 $objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0")
  159.                 If IsObj($objDoc) Then
  160.                     $DOMVERSION = $x
  161.                     ExitLoop
  162.                 EndIf
  163.             EndIf
  164.         Next
  165.     EndIf
  166.     If Not IsObj($objDoc) Then
  167.         _XMLError("Error: MSXML not found. This object is required to use this program.")
  168.         SetError(2)
  169.         Return -1
  170.     EndIf
  171.     ;Thanks Lukasz Suleja
  172.     $oXMLMyError = ObjEvent("AutoIt.Error")
  173.     If $oXMLMyError = "" Then
  174.         $oXMLMyError = ObjEvent("AutoIt.Error", "_XMLCOMEerr") ; ; Initialize SvenP 's error handler
  175.     EndIf
  176.     $strFile = $strXMLFile
  177.     $objDoc.async = False
  178.     $objDoc.preserveWhiteSpace = True
  179.     $objDoc.validateOnParse = $bValOnParse
  180.     if $DOMVERSION > 4 Then $objDoc.setProperty ("ProhibitDTD",false)
  181.     $objDoc.Load ($strFile)
  182.     $objDoc.setProperty ("SelectionLanguage", "XPath")
  183.     $objDoc.setProperty ("SelectionNamespaces", $strNameSpc)
  184.     if $objDoc.parseError.errorCode >0 Then consoleWrite($objDoc.parseError.reason&@LF)
  185.     If $objDoc.parseError.errorCode <> 0 Then
  186.         _XMLError("Error opening specified file: " & $strXMLFile & @CRLF & $objDoc.parseError.reason)
  187.         ;Tom Hohmann 2008/02/29
  188.         SetError(1,$objDoc.parseError.errorCode,-1)
  189.         $objDoc = 0
  190.         Return -1
  191.     EndIf
  192.     ;Tom Hohmann 2008/02/29
  193.     Return 1
  194. EndFunc   ;==>_XMLFileOpen
  195. ;===============================================================================
  196. ; Function Name:     _XMLLoadXML
  197. ; Description:      Creates an instance for a string of XML .
  198. ; Parameters:       $strXML - The XML to load into the document
  199. ; Syntax:            _XMLLoadXML($strXML)
  200. ; Return Value(s): On Success - 1
  201. ;                  On Failure - -1 and set @error to
  202. ;                     1 - failed to create object, @Extended = MSXML reason
  203. ;                     2 - no object found (MSXML required for _XML functions
  204. ;
  205. ; Author(s):        Stephen Podhajecki <[email protected]>,Lukasz Suleja,Tom Hohmann
  206. ;===============================================================================
  207. Func _XMLLoadXML($strXML,$strNameSpc="", $iVer = -1, $bValOnParse = True)
  208.     If $iVer <> -1 Then
  209.         If $iVer > -1 And $iVer < 7 Then
  210.             $objDoc = ObjCreate("Msxml2.DOMDocument." & $iVer & ".0")
  211.             If IsObj($objDoc) Then
  212.                 $DOMVERSION = $iVer
  213.             EndIf
  214.         Else
  215.             MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $iVer)
  216.             SetError(1)
  217.             Return 0
  218.         EndIf
  219.     Else
  220.         For $x = 8 To 0 Step - 1
  221.             If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then
  222.                 $objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0")
  223.                 If IsObj($objDoc) Then
  224.                     $DOMVERSION = $x
  225.                     ExitLoop
  226.                 EndIf
  227.             EndIf
  228.         Next
  229.     EndIf
  230.     If Not IsObj($objDoc) Then
  231.         _XMLError("Error: MSXML not found. This object is required to use this program.")
  232.         SetError(2)
  233.         Return -1
  234.     EndIf
  235.     ;Thanks Lukasz Suleja
  236.     $oXMLMyError = ObjEvent("AutoIt.Error")
  237.     If $oXMLMyError = "" Then
  238.         $oXMLMyError = ObjEvent("AutoIt.Error", "_XMLCOMEerr") ; ; Initialize SvenP 's error handler
  239.     EndIf
  240.     $objDoc.async = False
  241.     $objDoc.preserveWhiteSpace = True
  242.     $objDoc.validateOnParse = $bValOnParse
  243.     if $DOMVERSION > 4 Then $objDoc.setProperty ("ProhibitDTD",false)
  244.     $objDoc.LoadXml ($strXML)
  245.     $objDoc.setProperty ("SelectionLanguage", "XPath")
  246.     $objDoc.setProperty ("SelectionNamespaces", $strNameSpc); "xmlns:ms='urn:schemas-microsoft-com:xslt'"
  247.     If $objDoc.parseError.errorCode <> 0 Then
  248.         _XMLError("Error loading the XML data: " & @CRLF & $objDoc.parseError.reason)
  249.         ;Tom Hohmann 2008/02/29
  250.         SetError(1,$objDoc.parseError.errorCode, -1)
  251.         Return -1
  252.     EndIf
  253.     ;Tom Hohmann 2008/02/29
  254.     Return 1
  255. EndFunc   ;==>_MSXMLLoadXML
  256.  
  257. ;===============================================================================
  258. ; Function Name:    _XMLCreateFile
  259. ; Description:      Create a new blank metafile with header.
  260. ; Parameter(s): $strPath - The xml filename with full path to create
  261. ;                       $strRoot - The root of the xml file to create
  262. ;                   $bOverwrite -  boolean flag to auto overwrite existing file of same name.
  263. ;                       $bUTF8 - boolean flag to specify UTF-8 encoding in header.
  264. ; Syntax:           _XMLCreateFile($strPath,$strRoot,[$bOverwrite],[$bUTF8])
  265. ; Return Value(s):  On Success - 1
  266. ;                           On Failure  - -1 and sets
  267. ;                               @Error to:
  268. ;                                   0 = No error
  269. ;                                   1 = Failed to create file
  270. ;                                   2 = No object
  271. ;                                   3 = File creation failed MSXML error
  272. ;                                   4 = File exists
  273. ; Author(s):        Stephen Podhajecki <[email protected]>
  274. ;===============================================================================
  275. Func _XMLCreateFile($strPath, $strRoot, $bOverwrite = False, $bUTF8 = False, $ver = -1)
  276.     Local $retval, $fe, $objPI, $objDoc, $rootElement
  277.     $fe = FileExists($strPath)
  278.     If $fe And Not $bOverwrite Then
  279.         $retval = (MsgBox(4097, "File Exists:", "The specified file exits." & @CRLF & "Click OK to overwrite file or cancel to exit."))
  280.         If $retval = 1 Then
  281.             FileCopy($strPath, $strPath & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & "-" & @SEC & ".bak", 1)
  282.             FileDelete($strPath)
  283.             $fe = False
  284.         Else
  285.             _XMLError("Error failed to create file: " & $strPath & @CRLF & "File exists.")
  286.             SetError(4)
  287.             Return -1
  288.         EndIf
  289.     Else
  290.         FileCopy($strPath, $strPath & ".old", 1)
  291.         FileDelete($strPath)
  292.         $fe = False
  293.     EndIf
  294.     If $fe = False Then
  295.         If $ver <> -1 Then
  296.             If $ver > -1 And $ver < 7 Then
  297.                 $objDoc = ObjCreate("Msxml2.DOMDocument." & $ver & ".0")
  298.                 If IsObj($objDoc) Then
  299.                     $DOMVERSION = $ver
  300.                 EndIf
  301.             Else
  302.                 MsgBox(266288, "Error:", "Failed to create object with MSXML version " & $ver)
  303.                 SetError(3)
  304.                 Return 0
  305.             EndIf
  306.         Else
  307.             For $x = 8 To 0 Step - 1
  308.                 If FileExists(@SystemDir & "\msxml" & $x & ".dll") Then
  309.                     $objDoc = ObjCreate("Msxml2.DOMDocument." & $x & ".0")
  310.                     If IsObj($objDoc) Then
  311.                         $DOMVERSION = $x
  312.                         ExitLoop
  313.                     EndIf
  314.                 EndIf
  315.             Next
  316.         EndIf
  317.         If Not IsObj($objDoc) Then
  318.             Return SetError(2)
  319.         EndIf
  320.         If $bUTF8 Then
  321.             $objPI = $objDoc.createProcessingInstruction ("xml", "version=""1.0"" encoding=""UTF-8""")
  322.         Else
  323.             $objPI = $objDoc.createProcessingInstruction ("xml", "version=""1.0""")
  324.         EndIf
  325.         $objDoc.appendChild ($objPI)
  326.         $rootElement = $objDoc.createElement ($strRoot)
  327.         $objDoc.documentElement = $rootElement
  328.         $objDoc.save ($strPath)
  329.         If $objDoc.parseError.errorCode <> 0 Then
  330.             _XMLError("Error Creating specified file: " & $strPath)
  331. ;           Tom Hohmann 2008/02/29
  332.             SetError(1, $objDoc.parseError.errorCode, -1)
  333.             Return -1
  334.         EndIf
  335.         Return 1
  336.     Else
  337.         _XMLError("Error! Failed to create file: " & $strPath)
  338.         SetError(1)
  339.         Return 0
  340.     EndIf
  341.     Return 1
  342. EndFunc   ;==>_XMLCreateFile
  343. ;===============================================================================
  344. ; Function Name:    _XMLSelectNodes
  345. ; Description:      Selects XML Node(s) based on XPath input from root node.
  346. ; Parameter(s): $strXPath - xml tree path from root node (root/child/child..)
  347. ; Syntax:           _XMLSelectNode($strXPath)
  348. ; Return Value(s):  On Success - An array of Nodes(count is in first element)
  349. ;                           On Failure - -1 and set @Error = 1
  350. ; Author(s):        Stephen Podhajecki <[email protected]>
  351. ;===============================================================================
  352. Func _XMLSelectNodes($strXPath)
  353.     If not IsObj($objDoc) then
  354.         _XMLError("No object passed to function _XMLSelectNodes")
  355.         Return SetError(2,0,-1)
  356.     EndIf
  357.     Local $objNode, $objNodeList, $arrResponse[1], $xmlerr
  358.     $objNodeList = $objDoc.selectNodes ($strXPath)
  359.         If Not IsObj($objNodeList) Then
  360.             _XMLError("\nNo matching nodes found")
  361.             Return SetError(1,0,-1)
  362.         EndIf
  363.         If $objNodeList.length < 1 Then
  364.             _XMLError("\nNo matching nodes found")
  365.             Return SetError(1,0,-1)
  366.         EndIf
  367.         For $objNode In $objNodeList
  368.             _XMLArrayAdd($arrResponse, $objNode.nodeName)
  369.             _DebugWrite($objNode.nodeName)
  370.             _DebugWrite($objNode.namespaceURI)
  371.         Next
  372.         $arrResponse[0] = $objNodeList.length
  373.         Return $arrResponse
  374.     _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr)
  375.     Return SetError(1,0,-1)
  376. EndFunc   ;==>_XMLSelectNodes
  377. ;
  378. ;===============================================================================
  379. ; Function Name:    _XMLGetField
  380. ; Description:      Get XML Field(s) based on XPath input from root node.
  381. ; Parameter(s):     $path   xml tree path from root node (root/child/child..)
  382. ; Syntax:           _XMLGetField($path)
  383. ; Author(s):        Stephen Podhajecki <[email protected]>
  384. ; Return Value(s):  On Success  An array of fields text values(count is in first element)
  385. ;                           On Failure -1 set @Error = 1
  386. ;===============================================================================
  387. Func _XMLGetField($strXPath)
  388.     If not IsObj($objDoc) then
  389.         _XMLError("No object passed to function _XMLGetField")
  390.         Return SetError(1,2,-1)
  391.     EndIf
  392.     Local $objNodeList, $arrResponse[1], $xmlerr, $szNodePath
  393.         $objNodeList = $objDoc.selectSingleNode ($strXPath)
  394.         If Not IsObj($objNodeList) Then
  395.             _XMLError("\nNo Matching Nodes found")
  396.             $arrResponse[0] = 0
  397.             Return SetError(2,0,-1)
  398.         EndIf
  399.         If $objNodeList.hasChildNodes () Then
  400.             Local $count = $objNodeList.childNodes.length
  401.             For $x =1 to $count
  402.                 $objChild = $objNodeList.childNodes($x)
  403.                     _DebugWrite("ParentNode="&$objNodeList.parentNode.nodeType)
  404.                     If $objNodeList.parentNode.nodeType =$NODE_DOCUMENT Then
  405.                         $szNodePath="/"&$objNodeList.baseName &"/*["&$x&"]"
  406.                     Else
  407.                         $szNodePath = $objNodeList.baseName &"/*["&$x&"]"
  408.                     EndIf
  409.  
  410.                     $aRet = _XMLGetValue($szNodePath)
  411.                     If IsArray($aRet) Then
  412.                         If UBound($aRet) > 1 Then
  413.                             _XMLArrayAdd($arrResponse, $aRet[1])
  414.                             _DebugWrite("GetField>Text:" & $aRet[1])
  415.                         EndIf
  416.                     Else
  417.                         _XMLArrayAdd($arrResponse, "")
  418.                         _DebugWrite("GetField>Text:" & "")
  419.                     EndIf
  420.             Next
  421.             $arrResponse[0] = UBound($arrResponse) - 1
  422.             Return $arrResponse
  423.         Else
  424.             $arrResponse[0] = 0
  425.             _XMLError("\nNo Child Nodes found")
  426.             Return SetError(1,0,-1)
  427.         EndIf
  428.         _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr)
  429.     Return SetError(1,0,-1)
  430. EndFunc   ;==>_XMLGetField
  431. ;===============================================================================
  432. ; Function Name:    _XMLGetValue
  433. ; Description:  Get XML values based on XPath input from root node.
  434. ; Parameter(s):     $strXPath - xml tree path from root node (root/child/child..)
  435. ; Syntax:           _XMLGetValue($strXPath)
  436. ; Author(s):        Stephen Podhajecki <[email protected]>
  437. ; Return Value(s):  On Success  An array of fields text values(count is in first element)
  438. ;                           On Failure -1 set
  439. ;                               @Error = 1
  440. ;                               @Extended to:
  441. ;                                       0 = No matching node
  442. ;                                       1 = No object passed
  443. ;===============================================================================
  444. Func _XMLGetValue($strXPath)
  445.     If not IsObj($objDoc) then
  446.         ConsoleWrite("No obj pass to GetValue" & @CRLF)
  447.         _XMLError("No object passed to function _XMLGetValue")
  448.         Return SetError(1,1,-1)
  449.     EndIf
  450.     Local $objNodeList, $arrResponse[1], $objNodeChild, $xmlerr
  451.         _DebugWrite("GetValue>$strXPath:"&$strXPath)
  452.         $objNodeList = $objDoc.documentElement.selectNodes ($strXPath)
  453.         If $objNodeList.length > 0 Then
  454.             _DebugWrite("GetValue list length:" & $objNodeList.length)
  455.             For $objNode In $objNodeList
  456.                 If $objNode.hasChildNodes () = False Then
  457.                     _XMLArrayAdd($arrResponse, $objNode.nodeValue)
  458.                 Else
  459.                     For $objNodeChild In $objNode.childNodes ()
  460.                         If $objNodeChild.nodeType = $NODE_CDATA_SECTION Then
  461.                             _XMLArrayAdd($arrResponse, $objNodeChild.data)
  462.                             _DebugWrite("GetValue>CData:" & $objNodeChild.data)
  463.                         ElseIf $objNodeChild.nodeType = $NODE_TEXT Then
  464.                             _XMLArrayAdd($arrResponse, $objNodeChild.Text)
  465.                             _DebugWrite("GetValue>Text:" & $objNodeChild.Text)
  466.                         EndIf
  467.                     Next
  468.                 EndIf
  469.             Next
  470.             $arrResponse[0] = UBound($arrResponse) - 1
  471.             Return $arrResponse
  472.         Else
  473.             $xmlerr = @CRLF & "No matching node(s)found!"
  474.             Return SetError(1,0,-1)
  475.         EndIf
  476.     _XMLError("Error Retrieving: " & $strXPath & $xmlerr)
  477.  
  478.     Return SetError(1,0, -1)
  479. EndFunc   ;==>_XMLGetValue
  480. ;===============================================================================
  481. ; Function Name:    _XMLDeleteNode
  482. ; Description:      Deletes XML Node based on XPath input from root node.
  483. ; Parameter(s):     $path   xml tree path from root node (root/child/child..)
  484. ; Syntax:           _XMLDeleteNode($path)
  485. ; Author(s):        Stephen Podhajecki <[email protected]>
  486. ; Return Value(s):  On Success 1
  487. ;                           On Failure -1 and Sets
  488. ;                                   @Error to:
  489. ;                                       0 = No error
  490. ;                                       1 = Deletion error
  491. ;                                       2 = No object passed
  492. ;===============================================================================
  493. Func _XMLDeleteNode($strXPath)
  494.     If not IsObj($objDoc) then
  495.         _XMLError("No object passed to function _XMLDeleteNode")
  496.         Return SetError(2,0,-1)
  497.     EndIf
  498.     Local $objNode, $xmlerr
  499.     $objNode = $objDoc.selectNodes ($strXPath)
  500.     If Not IsObj($objNode) Then $xmlerr = @CRLF & "Node Not found"
  501.     if @error = 0 Then
  502.         For $objChild in $objNode
  503.             ConsoleWrite("Delete node " & $objChild.nodeName & @LF)
  504.             $objChild.parentNode.removeChild ($objChild)
  505.         Next
  506.         If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  507.         Return 1
  508.     EndIf
  509.     _XMLError("Error Deleting Node: " & $strXPath & $xmlerr)
  510.     Return SetError(1,0,-1)
  511. EndFunc   ;==>_XMLDeleteNode
  512.  
  513. ;===============================================================================
  514. ; Function Name:    _XMLDeleteAttr
  515. ; Description:      Delete XML Attribute based on XPath input from root node.
  516. ; Parameter(s): $strXPath xml tree path from root node (root/child/child..)
  517. ;                       $strAttribute The attribute node to delete
  518. ; Syntax:           _XMLDeleteAttr($strPath,$strAttribute)
  519. ; Author(s):        Stephen Podhajecki <[email protected]>
  520. ; Return Value(s):  On Success  1
  521. ;                           On Failure -1 and sets
  522. ;                               @Error to:
  523. ;                                   0 = No error
  524. ;                                   1 = Error removing attribute
  525. ;                                   2 = No object
  526. ;===============================================================================
  527. Func _XMLDeleteAttr($strXPath, $strAttrib)
  528.     If not IsObj($objDoc) then
  529.         _XMLError("No object passed to function _XMLDeleteAttr")
  530.         Return SetError(2,0,-1)
  531.     EndIf
  532. Local $objNode, $objAttr, $xmlerr
  533.     $objNode = $objDoc.selectSingleNode ($strXPath)
  534.     If IsObj($objNode) Then
  535.         $objAttr = $objNode.getAttributeNode ($strAttrib)
  536.         If Not (IsObj($objAttr)) Then
  537.             _XMLError("Attribute " & $strAttrib & " does not exist!")
  538.             Return SetError(2,0,-1)
  539.         EndIf
  540.         $objAttr = $objNode.removeAttribute ($strAttrib)
  541.                 If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  542.         Return 1
  543.     EndIf
  544.     _XMLError("Error Removing Attribute: " & $strXPath & " - " & $strAttrib & @CRLF & $xmlerr)
  545.     $xmlerr = ""
  546.     Return SetError(1,0,-1)
  547. EndFunc   ;==>_XMLDeleteAttr
  548. ;===============================================================================
  549. ; Function Name:    _XMLDeleteAttrNode
  550. ; Description:      Delete XML Attribute node based on XPath input from root node.
  551. ; Parameter(s): $strXpath xml tree path from root node (root/child/child..)
  552. ;                       $strAttribute The attribute node to delete
  553. ; Syntax:           _XMLDeleteAttrNode($strXPath,$strAttribute)
  554. ; Author(s):        Stephen Podhajecki <[email protected]>
  555. ; Return Value(s):  On Success  1
  556. ;                           On Failure -1 and sets
  557. ;                               @Error to:
  558. ;                                   0 = No error
  559. ;                                   1 = Error removing node
  560. ;                                   2 = No object
  561. ;===============================================================================
  562. Func _XMLDeleteAttrNode($strXPath, $strAttrib)
  563.     If not IsObj($objDoc) then
  564.         _XMLError("No object passed to function _XMLDeleteAttrNode")
  565.         Return SetError(2,0,-1)
  566.     EndIf
  567.     Local $objNode, $objAttr, $xmlerr
  568.     $objNode = $objDoc.selectSingleNode ($strXPath)
  569.     If Not IsObj($objNode) Then
  570.         _XMLError("\nSpecified node not found!")
  571.         Return SetError(2,0,-1)
  572.     EndIf
  573.     $objAttr = $objNode.removeAttributeNode ($objNode.getAttributeNode ($strAttrib))
  574.     If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  575.     If Not (IsObj($objAttr)) Then
  576.         _XMLError("\nUnspecified error:!")
  577.         Return SetError(1,0,-1)
  578.     EndIf
  579.     Return 1
  580. EndFunc   ;==>_XMLDeleteAttrNode
  581. ;===============================================================================
  582. ; Function Name:    _XMLGetAttrib
  583. ; Description:      Get XML Field based on XPath input from root node.
  584. ; Parameter(s):     $path   xml tree path from root node (root/child/child..)
  585. ; Syntax:           _XMLGetAttrib($path,$attrib)
  586. ; Author(s):        Stephen Podhajecki <[email protected]>
  587. ; Return Value(s): On Success  The attribute value.
  588. ;                        On Failure -1 and sets
  589. ;                               @Error to:
  590. ;                                   0 = No error
  591. ;                                   1 = Attribute not found.
  592. ;                                   2 = No object
  593. ;===============================================================================
  594. Func _XMLGetAttrib($strXPath, $strAttrib, $strQuery = "")
  595.     If not IsObj($objDoc) then
  596.         _XMLError("No object passed to function _XMLGetAttrib")
  597.         Return SetError(2,0,-1)
  598.     EndIf
  599.     ;Local $objNodeList, $arrResponse[1], $i, $xmlerr, $objAttr
  600.     Local $objNodeList, $arrResponse, $i, $xmlerr, $objAttr
  601.     $objNodeList = $objDoc.documentElement.selectNodes ($strXPath & $strQuery)
  602.     _DebugWrite("Get Attrib length= " & $objNodeList.length)
  603.     If $objNodeList.length > 0 Then
  604.         For $i = 0 To $objNodeList.length - 1
  605.             $objAttr = $objNodeList.item ($i).getAttribute ($strAttrib)
  606.             $arrResponse = $objAttr
  607.             _DebugWrite("RET>>" & $objAttr)
  608.         Next
  609.         Return $arrResponse
  610.     EndIf
  611.     $xmlerr = "\nNo qualified items found"
  612.     _XMLError("Attribute " & $strAttrib & " not found for: " & $strXPath & $xmlerr)
  613.     Return SetError(1,0,-1)
  614. EndFunc   ;==>_XMLGetAttrib
  615. ;===============================================================================
  616. ; Function Name:    _XMLSetAttrib
  617. ; Description:      Set XML Field(s) based on XPath input from root node.
  618. ; Parameter(s):     $path xml tree path from root node (root/child/child..)
  619. ;                   $attrib the attribute to set.
  620. ;                   $value the value to give the attribute defaults to ""
  621. ; Syntax:           _XMLSetAttrib($path,$attrib,$value)
  622. ; Author(s):        Stephen Podhajecki <[email protected]>
  623. ; Return Value(s)           array of fields text values
  624. ;                   on error returns -1 and sets error to 1
  625. ;===============================================================================
  626. Func _XMLSetAttrib($strXPath, $strAttrib, $strValue = "", $iIndex =-1)
  627.     If not IsObj($objDoc) then
  628.         _XMLError("No object passed to function _XMLSetAttrib")
  629.         Return SetError(1,8,-1)
  630.     EndIf
  631.     Local $objNodeList, $arrResponse[1], $i
  632.     $objNodeList = $objDoc.selectNodes ($strXPath)
  633.     _DebugWrite(" Node list Length: " & $objNodeList.length)
  634.     If @error = 0 And $objNodeList.length > 0 Then
  635.         If $iIndex > 0 Then
  636.             $arrResponse[0] = $objNodeList.item ($iIndex).SetAttribute ($strAttrib, $strValue)
  637.         Else
  638.             ReDim $arrResponse[$objNodeList.length]
  639.             For $i = 0 To $objNodeList.length - 1
  640.                 $arrResponse[$i] = $objNodeList.item ($i).SetAttribute ($strAttrib, $strValue)
  641.                 If $objDoc.parseError.errorCode <> 0 Then ExitLoop
  642.             Next
  643.         EndIf
  644.         If $objDoc.parseError.errorCode <> 0 Then
  645.             _XMLError("Error setting attribute for: " & $strXPath & @CRLF & $objDoc.parseError.reason)
  646.             Return SetError(1,$objDoc.parseError.errorCode,-1)
  647.         EndIf
  648.         If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  649.         Return $arrResponse
  650.     EndIf
  651.     _XMLError("Error failed to set attribute for: " & $strXPath & @CRLF)
  652.     SetError(1)
  653.     Return -1
  654. EndFunc   ;==>_XMLSetAttrib
  655. ;===============================================================================
  656. ; Function Name:    _XMLGetAllAttrib
  657. ; Description:      Get all XML Field(s) attributes based on XPath input from root node.
  658. ; Parameter(s):     $path   xml tree path from root node (root/child/child..)
  659. ;                   $query the query string in xml format
  660. ;                   $names the array to return the attrib names
  661. ;                   $value the array to return the attrib values
  662. ;                   [$query] DOM compliant query string (not really necessary as it becomes
  663. ;part of the path
  664. ; Syntax:           _XMLGetAllAttrib($path,$query)
  665. ; Author(s):        Stephen Podhajecki <[email protected]>
  666. ; Return Value(s)           array of fields text values(number of items is in [0][0]
  667. ;                   on error set error to 1 and returns -1
  668. ;===============================================================================
  669. Func _XMLGetAllAttrib($strXPath, ByRef $aName, ByRef $aValue, $strQry = "")
  670.     If not IsObj($objDoc) then
  671.         _XMLError("No object passed to function _XMLGetAllAttrib")
  672.         Return SetError(1,9,-1)
  673.     EndIf
  674.     Local $objNodeList, $objQueryNodes, $objNode, $arrResponse[2][1], $i
  675.     $objQueryNodes = $objDoc.selectNodes ($strXPath & $strQry)
  676.     If $objQueryNodes.length > 0 Then
  677.         For $objNode In $objQueryNodes
  678.             $objNodeList = $objNode.attributes
  679.             If ($objNodeList.length) Then
  680.                 _DebugWrite("Get all attrib " & $objNodeList.length)
  681.                 ReDim $arrResponse[2][$objNodeList.length + 2]
  682.                 ReDim $aName[$objNodeList.length]
  683.                 ReDim $aValue[$objNodeList.length]
  684.                 For $i = 0 To $objNodeList.length - 1
  685.                     $arrResponse[0][$i + 1] = $objNodeList.item ($i).nodeName
  686.                     $arrResponse[1][$i + 1] = $objNodeList.item ($i).Value
  687.                     $aName[$i] = $objNodeList.item ($i).nodeName
  688.                     $aValue[$i] = $objNodeList.item ($i).Value
  689.                 Next
  690.             Else
  691.                 _XMLError("No Attributes found for node")
  692.                 Return SetError(1,0, -1)
  693.             EndIf
  694.         Next
  695.         $arrResponse[0][0] = $objNodeList.length
  696.         Return $arrResponse
  697.     EndIf
  698.     _XMLError("Error retrieving attributes for: " & $strXPath & @CRLF)
  699.     return SetError(1,0 ,-1)
  700.     ;   EndIf
  701. EndFunc   ;==>_XMLGetAllAttrib
  702. ;===============================================================================
  703. ; Function Name:    _XMLUpdateField
  704. ; Description:      Update existing node(s) based on XPath specs.
  705. ; Parameter(s):     $path   Path from root node
  706. ;                   $new_data   Data to update node with
  707. ; Syntax:           _XMLUpdateField($path,$new_data)
  708. ; Author(s):        Stephen Podhajecki <[email protected]>
  709. ; Return Value(s)           on error set error to 1 and returns -1
  710. ;===============================================================================
  711. Func _XMLUpdateField($strXPath, $strData)
  712.     If not IsObj($objDoc) then
  713.         _XMLError("No object passed to function _XMLUpdateField")
  714.         Return SetError(1,9,-1)
  715.     EndIf
  716.     Local $objField, $bUpdate, $objNode
  717.     #forceref $objField
  718.     $objField = $objDoc.selectSingleNode ($strXPath)
  719.     If IsObj($objField) Then
  720.         If $objField.hasChildNodes Then
  721.             For $objChild In $objField.childNodes ()
  722.                 If $objChild.nodetype = $NODE_TEXT Then
  723.                     $objChild.Text = $strData
  724.                     $bUpdate = True
  725.                     ExitLoop
  726.                 EndIf
  727.             Next
  728.         EndIf
  729.         if $bUpdate = False Then
  730.             $objNode = $objDoc.createTextNode($strData)
  731.             $objField.appendChild($objNode)
  732.         EndIf
  733.         If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  734.         $objField = ""
  735.         Return
  736.     EndIf
  737.     _XMLError("Failed to update field for: " & $strXPath & @CRLF)
  738.     Return SetError(1,0,-1)
  739.  
  740. EndFunc   ;==>_XMLUpdateField
  741. ;===============================================================================
  742. ; Function Name: _XMLCreateCDATA
  743. ; Description: Create a CDATA SECTION node directly under root.
  744. ; Parameter(s): $node name of node to create
  745. ; $data CDATA value
  746. ; Syntax: _XMLCreateCDATA($node,$data)
  747. ; Author(s): Stephen Podhajecki <[email protected]>
  748. ; Return Value(s):on error set error to 1 and returns -1
  749. ; fixme, won't append to exisiting node. must create new node.
  750. ;===============================================================================
  751. Func _XMLCreateCDATA($strNode, $strCDATA, $strNameSpc = "")
  752.     If not IsObj($objDoc) then
  753.         _XMLError("No object passed to function _XMLCreateCDATA")
  754.         Return SetError(1,10,-1)
  755.     EndIf
  756.     Local $objChild, $objNode
  757.     $objNode = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
  758.     If IsObj($objNode) Then
  759.         If Not ($objNode.hasChildNodes ()) Then
  760.             _AddFormat($objDoc, $objNode)
  761.         EndIf
  762.         $objChild = $objDoc.createCDATASection ($strCDATA)
  763.         $objNode.appendChild ($objChild)
  764.         $objDoc.documentElement.appendChild ($objNode)
  765.                 If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  766.         _AddFormat($objDoc)
  767.         $objChild = ""
  768.         Return 1
  769.     EndIf
  770.     _XMLError("Failed to create CDATA Section: " & $strNode & @CRLF)
  771.     Return SetError(1, 0 ,-1)
  772. EndFunc   ;==>_XMLCreateCDATA
  773. ;===============================================================================
  774. ; Function Name:    _XMLCreateComment
  775. ; Description:      Create a COMMENT node at specified path.
  776. ; Parameter(s):     $node   name of node to create
  777. ;                   $comment the comment to add the to the xml file
  778. ; Syntax:           _XMLCreateComment($node,$comment)
  779. ; Author(s):        Stephen Podhajecki <[email protected]>
  780. ; Return Value(s)           on error set error to 1 and returns -1
  781. ;===============================================================================
  782. Func _XMLCreateComment($strNode, $strComment)
  783.     If not IsObj($objDoc) then
  784.         _XMLError("No object passed to function _XMLCreateComment")
  785.         Return SetError(1,11,-1)
  786.     EndIf
  787.     Local $objChild, $objNode
  788.  
  789.     $objNode = $objDoc.selectSingleNode ($strNode)
  790.     If IsObj($objNode) Then
  791.         If Not ($objNode.hasChildNodes ()) Then
  792.             _AddFormat($objDoc, $objNode)
  793.         EndIf
  794.         $objChild = $objDoc.createComment ($strComment)
  795.         $objNode.insertBefore ($objChild, $objNode.childNodes (0))
  796.                 If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  797.         _AddFormat($objDoc)
  798.         $objChild = ""
  799.         Return 1
  800.     EndIf
  801.     _XMLError("Failed to root child: " & $strNode & @CRLF)
  802.     Return SetError(1,0, -1)
  803. EndFunc   ;==>_XMLCreateComment
  804. ;===============================================================================
  805. ; Function Name:    _XMLCreateAttribute
  806. ; Description:
  807. ; Parameter(s):     $strXPath xml tree path from root node (root/child/child..)
  808. ;                       $strAttrName the attribute to set.
  809. ;                       $strAttrValue the value to give the attribute defaults to ""
  810. ; Syntax:            _XMLCreateAttrib($strXPath,$strAttrName,$strAttrValue="")
  811. ; Author(s):        Stephen Podhajecki <[email protected]>
  812. ; Return Value(s)           1 on success, 0 on error
  813. ;===============================================================================
  814. Func _XMLCreateAttrib($strXPath, $strAttrName, $strAttrValue = "")
  815.     If not IsObj($objDoc) then
  816.         _XMLError("No object passed to function _XMLCreateAttrib")
  817.         Return SetError(1,12,-1)
  818.     EndIf
  819.     Local $objNode, $objAttr, $objAttrVal, $err
  820.     $objNode = $objDoc.selectSingleNode ($strXPath)
  821.     If IsObj($objNode) Then
  822.         $objAttr = $objDoc.createAttribute ($strAttrName);, $strNameSpc)
  823.         $objNode.SetAttribute ($strAttrName, $strAttrValue)
  824.                 If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  825.         $objAttr = 0
  826.         $objAttrVal = 0
  827.         $objNode = 0
  828.         $err = $objDoc.parseError.errorCode
  829.         If $err = 0 Then Return 1
  830.     EndIf
  831.     _XMLError("Error creating Attribute: " & $strAttrName & @CRLF & $strXPath & " does not exist." & @CRLF)
  832.     Return 0
  833. EndFunc   ;==>_XMLCreateAttrib
  834. ;===============================================================================
  835. ; Function Name:    _XMLCreateRootChild
  836. ; Description:      Create node directly under root.
  837. ; Parameter(s):     $node   name of node to create
  838. ;                   $value optional value to create
  839. ; Syntax:           _XMLCreateRootChild($node,[$value])
  840. ; Author(s):        Stephen Podhajecki <[email protected]>
  841. ; Return Value(s)           on error set error to 1 and returns -1
  842. ;===============================================================================
  843. Func _XMLCreateRootChild($strNode, $strData = "", $strNameSpc = "")
  844.     If not IsObj($objDoc) then
  845.         _XMLError("No object passed to function _XMLCreateRootChild")
  846.         Return SetError(1,14,-1)
  847.     EndIf
  848.     ConsoleWrite("_XMLCreateRootChild:"&$strNode&@LF)
  849.     Local $objChild
  850.     If Not ($objDoc.documentElement.hasChildNodes ()) Then
  851.         _AddFormat($objDoc)
  852.     EndIf
  853.     $objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
  854.     If IsObj($objChild) Then
  855.     If $strData <> "" Then $objChild.text = $strData
  856.         $objDoc.documentElement.appendChild ($objChild)
  857.                 If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  858.         _AddFormat($objDoc)
  859.         $objChild = 0
  860.         Return 1
  861.     EndIf
  862.     _XMLError("Failed to root child: " & $strNode & @CRLF)
  863.     Return SetError(1,0,-1)
  864. EndFunc   ;==>_XMLCreateRootChild
  865. ;===============================================================================
  866. ; Function Name:    _XMLCreateRootNodeWAttr
  867. ; Description:      Create a child node under root node with attributes.
  868. ; Parameter(s):     $node node to add with attibute(s)
  869. ;                   $[array]attrib attribute name(s) -- can be array
  870. ;                   $[array]value   attribute value(s) -- can be array
  871. ;                   $data   optional value to give the node.
  872. ; Requirements      This function requires that each attribute name has
  873. ;                   a corresponding value.
  874. ; Syntax:           _XMLCreateRootNodeWAttr($node,$array_attribs,$array_value)
  875. ; Author(s):        Stephen Podhajecki <[email protected]>
  876. ; Return Value(s)           on error set error to 1 or 2 and returns -1
  877. ;===============================================================================
  878. Func _XMLCreateRootNodeWAttr($strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "")
  879.     If not IsObj($objDoc) then
  880.         _XMLError("No object passed to function _XMLCreateRootNodeWAttr" & @CRLF)
  881.         ConsoleWrite("No object passed to function _XMLCreateRootNodeWAttr")
  882.         Return SetError(1,15,-1)
  883.     EndIf
  884.     Local $objChild, $objAttr, $objAttrVal
  885.     $objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
  886.     If IsObj($objChild) Then
  887.         If $strData <> "" Then $objChild.text = $strData
  888.         If Not ($objDoc.documentElement.hasChildNodes ()) Then
  889.             _AddFormat($objDoc)
  890.         EndIf
  891.         If IsArray($aAttr) And IsArray($aVal) Then
  892.             If UBound($aAttr) <> UBound($aVal) Then
  893.                 _XMLError("Attribute and value mismatch" & @CRLF & "Please make sure each attribute has a matching value.")
  894.                 ConsoleWrite("Attribute and value mismatch" & @CRLF & "Please make sure each attribute has a matching value." & @CRLF)
  895.                 SetError(2)
  896.                 Return -1
  897.             Else
  898.                 Local $i
  899.                 For $i = 0 To UBound($aAttr) - 1
  900.                     ConsoleWrite("$i = " & $i & @CRLF)
  901.                     If $aAttr[$i] = "" Then
  902.                         _XMLError("Error creating child node: " & $strNode & @CRLF & " Attribute Name Cannot be NULL." & @CRLF)
  903.                         ConsoleWrite("Error creating child node: " & $strNode & @CRLF & " Attribute Name Cannot be NULL." & @CRLF)
  904.                         Return SetError(1,0,-1)
  905.                     EndIf
  906.                     $objAttr = $objDoc.createAttribute ($aAttr[$i]);, $strNameSpc)
  907.                     $objChild.SetAttribute ($aAttr[$i], $aVal[$i])
  908.                 Next
  909.             EndIf
  910.         Else
  911.             $objAttr = $objDoc.createAttribute ($aAttr)
  912.             $objChild.SetAttribute ($aAttr, $aVal)
  913.         EndIf
  914.         $objDoc.documentElement.appendChild ($objChild)
  915.                 If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  916.         _AddFormat($objDoc)
  917.         $objChild = 0
  918.         Return 1
  919.     EndIf
  920.     _XMLError("Failed to create root child with attributes: " & $strNode & @CRLF)
  921.     ConsoleWrite("Failed to create root child with attributes: " & $strNode & @CRLF)
  922.     Return SetError(1,0,-1)
  923. EndFunc   ;==>_XMLCreateRootNodeWAttr
  924. ;===============================================================================
  925. ; Function Name:    _XMLCreateChildNode
  926. ; Description:      Create a child node under the specified XPath Node.
  927. ; Parameter(s):     $path   Path from root
  928. ;                   $node   Node to add
  929. ; Syntax:           _XMLCreateChildNode($path,$node)
  930. ; Author(s):        Stephen Podhajecki <[email protected]>
  931. ; Return Value(s)           on error set error to 1 and returns -1
  932. ;===============================================================================
  933. Func _XMLCreateChildNode($strXPath, $strNode, $strData = "", $strNameSpc = "")
  934.     If not IsObj($objDoc) then
  935.         _XMLError("No object passed to function _XMLCreateChildNode")
  936.         Return SetError(1,16,-1)
  937.     EndIf
  938.     Local $objParent, $objChild, $objNodeList
  939.         $objNodeList = $objDoc.selectNodes ($strXPath)
  940.         If IsObj($objNodeList) And $objNodeList.length > 0 Then
  941.             For $objParent In $objNodeList
  942.                 If Not ($objParent.hasChildNodes ()) Then
  943.                     _AddFormat($objDoc, $objParent)
  944.                 EndIf
  945.                 If $strNameSpc = "" Then
  946.                     If Not ($objParent.namespaceURI = 0 Or $objParent.namespaceURI = "") Then $strNameSpc = $objParent.namespaceURI
  947.                 EndIf
  948.                 ;ConsoleWrite("$strNameSpc=" & $strNameSpc & @LF)
  949.                 $objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
  950.                 If $strData <> "" Then $objChild.text = $strData
  951.                 $objParent.appendChild ($objChild)
  952.                 _AddFormat($objDoc, $objParent)
  953.             Next
  954.             If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  955.             $objParent = ""
  956.             $objChild = ""
  957.             Return 1
  958.         EndIf
  959.     _XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF)
  960.     Return SetError(1,0,-1)
  961. EndFunc   ;==>_XMLCreateChildNode
  962. ;===============================================================================
  963. ; Function Name:    _XMLCreateChildNodeWAttr
  964. ; Description:      Create a child node(s) under the specified XPath Node with attributes.
  965. ; Parameter(s):     $sPath Path from root
  966. ;                   $sNode node to add with attibute(s)
  967. ;                   $[array]attrib attribute name(s) -- can be array
  968. ;                   $[array]value   attribute value(s) -- can be array
  969. ;                   $data           Optional value to give the child node.
  970. ; Requirements      This function requires that each attribute name has
  971. ;                   a corresponding value.
  972. ; Syntax:           _XMLCreateChildNodeWAttr($path,$node,$[array]attrib,$]array]value)
  973. ; Author(s):        Stephen Podhajecki <[email protected]>
  974. ; Return Value(s)           0 on error and set error 1 or 2
  975. ;===============================================================================
  976. Func _XMLCreateChildNodeWAttr($strXPath, $strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "")
  977.     Return _XMLCreateChildWAttr($strXPath, $strNode, $aAttr, $aVal, $strData, $strNameSpc)
  978. EndFunc   ;==>_XMLCreateChildNodeWAttr
  979. ;===============================================================================
  980. ; Function Name:    _XMLCreateChildWAttr
  981. ; Description:      Create a child node(s) under the specified XPath Node with attributes.
  982. ; Parameter(s):     $sPath Path from root
  983. ;                   $sNode node to add with attibute(s)
  984. ;                   $[array]attrib attribute name(s) -- can be array
  985. ;                   $[array]value   attribute value(s) -- can be array
  986. ;                   $data           Optional value to give the child node.
  987. ; Requirements      This function requires that each attribute name has
  988. ;                   a corresponding value.
  989. ; Syntax:           _XMLCreateChildWAttr($path,$node,$[array]attrib,$]array]value)
  990. ; Author(s):        Stephen Podhajecki <[email protected]>
  991. ; Return Value(s)           0 on error and set error 1 or 2
  992. ;===============================================================================
  993. Func _XMLCreateChildWAttr($strXPath, $strNode, $aAttr, $aVal, $strData = "", $strNameSpc = "")
  994.     If not IsObj($objDoc) then
  995.         _XMLError("No object passed to function _XMLCreateChildWAttr")
  996.         Return SetError(1,18,-1)
  997.     EndIf
  998.     Local $objParent, $objChild, $objAttr, $objAttrVal, $objNodeList
  999.         $objNodeList = $objDoc.selectNodes ($strXPath)
  1000.         _DebugWrite("Node Selected")
  1001.         If IsObj($objNodeList) And $objNodeList.length <> 0 Then
  1002.             _DebugWrite("Entering if")
  1003.             For $objParent In $objNodeList
  1004.                 If Not ($objParent.hasChildNodes ()) Then
  1005.                     _AddFormat($objDoc, $objParent)
  1006.                 EndIf
  1007.                 _DebugWrite("Entering for")
  1008.                 If $strNameSpc = "" Then
  1009.                     If Not ($objParent.namespaceURI = 0 Or $objParent.namespaceURI = "") Then $strNameSpc = $objParent.namespaceURI
  1010.                 EndIf
  1011.                 $objChild = $objDoc.createNode ($NODE_ELEMENT, $strNode, $strNameSpc)
  1012.                 If @error Then Return -1
  1013.                 If $strData <> "" Then $objChild.text = $strData
  1014.                 If IsArray($aAttr) And IsArray($aVal) Then
  1015.                     If UBound($aAttr) <> UBound($aVal) Then
  1016.                         _XMLError("Attribute and value mismatch" & @CRLF & "Please make sure each attribute has a matching value.")
  1017.                         Return SetError(2,0,-1)
  1018.                     Else
  1019.                         Local $i
  1020.                         For $i = 0 To UBound($aAttr) - 1
  1021.                             _DebugWrite("Entering inside for")
  1022.                             If $aAttr[$i] = "" Then
  1023.                                 _XMLError("Error creating child node: " & $strNode & @CRLF & " Attribute Name Cannot be NULL." & @CRLF)
  1024.                                 SetError(1)
  1025.                                 Return -1
  1026.                             EndIf
  1027.                             _DebugWrite($aAttr[$i] & " " & $strNameSpc)
  1028.                             $objAttr = $objDoc.createAttribute ($aAttr[$i]);, $strNameSpc)
  1029.                             If @error Then ExitLoop
  1030.                             $objChild.SetAttribute ($aAttr[$i], $aVal[$i])
  1031.                             If @error <> 0 Then
  1032.                                 _XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF)
  1033.                                 Return SetError(1,0,-1)
  1034.                             EndIf
  1035.                             _DebugWrite("Looping inside for")
  1036.                         Next
  1037.                     EndIf
  1038.                 Else
  1039.                     If IsArray($aAttr) Or IsArray($aVal) Then
  1040.                         _XMLError("Type non-Array and Array detected" & @LF)
  1041.                         Return SetError(1,0,-1)
  1042.                     EndIf
  1043.                     If $aAttr = "" Then
  1044.                         _XMLError("Attribute Name cannot be empty string." & @LF)
  1045.                         Return SetError(5,0,-1)
  1046.                     EndIf
  1047.                     _DebugWrite($aAttr & " " & $strNameSpc)
  1048.                     $objAttr = $objDoc.createAttribute ($aAttr);, $strNameSpc)
  1049.                     $objChild.SetAttribute ($aAttr, $aVal)
  1050.                 EndIf
  1051.                 $objParent.appendChild ($objChild)
  1052.                 _DebugWrite("Looping for")
  1053.             Next
  1054.             _AddFormat($objDoc, $objParent)
  1055.                     If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  1056.             _DebugWrite("Saved")
  1057.             $objParent = ""
  1058.             $objChild = ""
  1059.             _DebugWrite("Returning")
  1060.             Return
  1061.         EndIf
  1062.     _XMLError("Error creating child node: " & $strNode & @CRLF & $strXPath & " does not exist." & @CRLF)
  1063.     Return SetError(1,0,-1)
  1064. EndFunc   ;==>_XMLCreateChildWAttr
  1065. ;===============================================================================
  1066. ; Function Name:    _XMLGetChildText
  1067. ; Description:      Selects XML child Node(s) of an element based on XPath input from root node.
  1068. ; Parameter(s):     $path   xml tree path from root node (root/child/child..)
  1069. ; Syntax:           _XMLGetChildText($path)
  1070. ; Author(s):        Stephen Podhajecki <[email protected]>
  1071. ; Return Value(s)           array of Nodes or -1 on failure
  1072. ;===============================================================================
  1073. Func _XMLGetChildText($strXPath)
  1074.     If not IsObj($objDoc) then
  1075.         _XMLError("No object passed to function _XMLGetChildText")
  1076.         Return SetError(1,19,-1)
  1077.     EndIf
  1078.     Local $objNodeList, $arrResponse[1], $xmlerr
  1079.         $objNodeList = $objDoc.selectSingleNode ($strXPath)
  1080.         If Not IsObj($objNodeList) Then
  1081.             _XMLError(@CRLF & "No Matching Nodes found")
  1082.             $arrResponse[0] = 0
  1083.             Return SetError(1,0,-1)
  1084.         EndIf
  1085.         If $objNodeList.hasChildNodes () Then
  1086.             For $objChild In $objNodeList.childNodes ()
  1087.                 If $objChild.nodeType = $NODE_ELEMENT Then
  1088.                     _XMLArrayAdd($arrResponse, $objChild.baseName)
  1089.                 ElseIf $objChild.nodeType = $NODE_TEXT Then
  1090.                     _XMLArrayAdd($arrResponse, $objChild.text)
  1091.                 EndIf
  1092.             Next
  1093.             $arrResponse[0] = UBound($arrResponse) - 1
  1094.             Return $arrResponse
  1095.         EndIf
  1096.     $arrResponse[0] = 0
  1097.     $xmlerr = @CRLF & "No Child Text Nodes found"
  1098.     _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr)
  1099.     Return SetError(1,0,-1)
  1100. EndFunc   ;==>_XMLGetChildText
  1101. ;===============================================================================
  1102. ; Function Name:    _XMLGetChildNodes
  1103. ; Description:      Selects XML child Node(s) of an element based on XPath input from root node.
  1104. ; Parameter(s):     $path   xml tree path from root node (root/child/child..)
  1105. ; Syntax:           _XMLGetChildNodes($path)
  1106. ; Author(s):        Stephen Podhajecki <[email protected]>
  1107. ; Return Value(s)           array of Nodes or -1 on failure
  1108. ;===============================================================================
  1109. Func _XMLGetChildNodes($strXPath)
  1110.     If not IsObj($objDoc) then
  1111.         _XMLError("No object passed to function _XMLGetChildNodes")
  1112.         Return SetError(1,20,-1)
  1113.     EndIf
  1114.     Local $objNodeList, $arrResponse[1], $xmlerr
  1115.     $objNodeList = $objDoc.selectSingleNode ($strXPath)
  1116.     If Not IsObj($objNodeList) Then
  1117.         _XMLError(@LF & "No Matching Nodes found")
  1118.         $arrResponse[0] = 0
  1119.         Return SetError(1,0,-1)
  1120.     EndIf
  1121.     If $objNodeList.hasChildNodes () Then
  1122.         For $objChild In $objNodeList.childNodes ()
  1123.             If $objChild.nodeType () = $NODE_ELEMENT Then
  1124.                 _DebugWrite($objChild.NamespaceURI &"::"& $objChild.baseName &@LF)
  1125.                 _XMLArrayAdd($arrResponse, $objChild.baseName)
  1126.             EndIf
  1127.         Next
  1128.         $arrResponse[0] = UBound($arrResponse) - 1
  1129.         Return $arrResponse
  1130.     EndIf
  1131.     $arrResponse[0] = 0
  1132.     $xmlerr = @LF & "No Child Nodes found"
  1133.     _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr)
  1134.     Return SetError(1,0,-1)
  1135. EndFunc   ;==>_XMLGetChildNodes
  1136. ;===============================================================================
  1137. ; Function Name:    _XMLGetChildren
  1138. ; Description:      Selects XML child Node(s) of an element based on XPath input from root node.
  1139. ;                       And returns there text values.
  1140. ; Parameter(s):     $path   xml tree path from root node (root/child/child..)
  1141. ; Syntax:           _XMLGetChildren($path)
  1142. ; Return Value(s):  On Success an array where
  1143. ;                       $array[0][0] = Size of array
  1144. ;                       $array[1][0] = Name
  1145. ;                       $array[1][1] = Text
  1146. ;                       $array[1][2] = NameSpaceURI
  1147. ;                       ...
  1148. ;                       $array[n][0] = Name
  1149. ;                       $array[n][1] = Text
  1150. ;                       $array[n][2] = NamespaceURI
  1151. ;                   On Failure  - Returns -1 and sets @ERROR to
  1152. ;                       1 - Failure
  1153. ; Author(s):        Stephen Podhajecki <[email protected]>
  1154. ;===============================================================================
  1155. Func _XMLGetChildren($strXPath)
  1156.     If not IsObj($objDoc) then
  1157.         _XMLError("No object passed to function _XMLGetChildren")
  1158.         Return SetError(1,21,-1)
  1159.     EndIf
  1160.     Local $objNodeList, $arrResponse[1][3], $xmlerr
  1161.     $objNodeList = $objDoc.selectSingleNode ($strXPath)
  1162.     If Not IsObj($objNodeList) Then
  1163.         _XMLError(@LF & "No Matching Nodes found")
  1164.         $arrResponse[0][0]= 0
  1165.         Return SetError(1,0,-1)
  1166.     EndIf
  1167.     If $objNodeList.hasChildNodes () Then
  1168.         For $objChild In $objNodeList.childNodes ()
  1169.             If $objChild.nodeType () = $NODE_ELEMENT Then
  1170.                 Local $dims = UBound($arrResponse,1)
  1171.                 ReDim $arrResponse[$dims+1][3]
  1172.                 $arrResponse[$dims][0] = $objChild.baseName
  1173.                 $arrResponse[$dims][1] = $objChild.text
  1174.                 $arrResponse[$dims][2] = $objChild.NamespaceURI
  1175.                 ;_XMLArrayAdd($arrResponse, $objChild.baseName)
  1176.             EndIf
  1177.         Next
  1178.         $arrResponse[0][0] = UBound($arrResponse,1) - 1
  1179.         Return $arrResponse
  1180.     EndIf
  1181.     $arrResponse[0][0] = 0
  1182.     $xmlerr = @LF & "No Child Nodes found"
  1183.     _XMLError("Error Selecting Node(s): " & $strXPath & $xmlerr)
  1184.     Return SetError(1,0,-1)
  1185. EndFunc   ;==>_XMLGetChildren
  1186.  
  1187. ;===============================================================================
  1188. ; Function Name: _XMLGetNodeCount
  1189. ; Description: Get Node Count based on XPath input from root node.
  1190. ; Parameter(s): $path xml tree path from root node (root/child/child..)
  1191. ; [$query] DOM compliant query string (not really necessary as it becomes part of the path
  1192. ;                   $iNodeType The type of node to count. (element, attrib, comment etc.)
  1193. ; Syntax: _XMLGetNodeCount($path,$query,$iNodeType)
  1194. ; Author(s): Stephen Podhajecki <[email protected]> & DickB
  1195. ; Return Value(s):0 or Number of Nodes found
  1196. ; on error set error to 1 and returns -1
  1197. ;===============================================================================
  1198. Func _XMLGetNodeCount($strXPath, $strQry = "", $iNodeType = 1)
  1199.     If not IsObj($objDoc) then
  1200.         _XMLError("No object passed to function _XMLGetNodeCount")
  1201.         Return SetError(1,22,-1)
  1202.     EndIf
  1203.     Local $objQueryNodes, $objNode, $nodeCount = 0, $errMsg
  1204.     $objQueryNodes = $objDoc.selectNodes ($strXPath & $strQry)
  1205.     If @error = 0 And $objQueryNodes.length > 0 Then
  1206.         For $objNode In $objQueryNodes
  1207.             If $objNode.nodeType = $iNodeType Then $nodeCount = $nodeCount + 1
  1208.         Next
  1209.         Return $nodeCount
  1210.     Else
  1211.         $errMsg = "No nodes of specified type found."
  1212.     EndIf
  1213.     _XMLError("Error retrieving node count for: " & $strXPath & @CRLF & $errMsg & @CRLF)
  1214.     SetError(1)
  1215.     Return -1
  1216.     ; EndIf
  1217. EndFunc   ;==>_XMLGetNodeCount
  1218. ;===============================================================================
  1219. ; Function Name:    _XMLGetAllAttribIndex
  1220. ; Description:      Get all XML Field(s) attributes based on Xpathn and specific index.
  1221. ; Parameter(s):     $sXpath xml tree path from root node (root/child/child..)
  1222. ;                   $aNames the array to return the attrib names
  1223. ;                   $aValue the array to return the attrib values
  1224. ;                   [$sQuery] DOM compliant query string (not really necessary as it becomes
  1225. ;                   [$iNode] node index.
  1226. ;part of the path
  1227. ; Syntax:           _XMLGetAllAttribIndex($path,$aNames,$aValues,[$sQuery="",$iNode=0]])
  1228. ; Author(s):        Stephen Podhajecki <[email protected]>
  1229. ; Return Value(s)           array of attrib node names, array of attrib values
  1230. ;                   on error set error to 1 and returns -1
  1231. ;===============================================================================
  1232. Func _XMLGetAllAttribIndex($strXPath, ByRef $aName, ByRef $aValue, $strQry = "", $NodeIndex = 0)
  1233.     If not IsObj($objDoc) then
  1234.         _XMLError("No object passed to function _XMLGetAllAttribIndex")
  1235.         Return SetError(1,23,-1)
  1236.     EndIf
  1237.     Local $objNodeList, $objQueryNodes, $arrResponse[2][1], $i
  1238.     $objQueryNodes = $objDoc.selectNodes ($strXPath & $strQry)
  1239.     If $objQueryNodes.length > 0 Then
  1240.         $objNodeList = $objQueryNodes.item($NodeIndex).attributes
  1241.         _DebugWrite("GetAllAttribIndex " & $objNodeList.length)
  1242.         ReDim $arrResponse[2][$objNodeList.length + 1]
  1243.         ReDim $aName[$objNodeList.length]
  1244.         ReDim $aValue[$objNodeList.length]
  1245.         For $i = 0 To $objNodeList.length - 1
  1246.             $arrResponse[0][$i] = $objNodeList.item ($i).nodeName
  1247.             $arrResponse[1][$i] = $objNodeList.item ($i).Value
  1248.             $aName[$i] = $objNodeList.item ($i).nodeName
  1249.             $aValue[$i] = $objNodeList.item ($i).Value
  1250.         Next
  1251.         Return $arrResponse
  1252.     EndIf
  1253.     _XMLError("Error retrieving attributes for: " & $strXPath & @CRLF)
  1254.     Return SetError(1,0,-1)
  1255. EndFunc   ;==>_XMLGetAllAttribIndex
  1256. ;===============================================================================
  1257. ; Function Name: _XMLGetPath
  1258. ; Description: Return a nodes full path based on XPath input from root node.
  1259. ; Parameter(s): $path xml tree path from root node (root/child/child..)
  1260. ; Syntax: _XMLGetPath($path)
  1261. ; Author(s): Stephen Podhajecki <[email protected]>
  1262. ; Return Value(s): array of fields text values -1 on failure
  1263. ;===============================================================================
  1264. Func _XMLGetPath($strXPath)
  1265.     If not IsObj($objDoc) then
  1266.         _XMLError("No object passed to function _XMLGetPath")
  1267.         Return SetError(1,24,-1)
  1268.     EndIf
  1269.     If $DOMVERSION < 4 Then
  1270.         _XMLError("Error DOM Version: " & "MSXML Version 4 or greater required for this function")
  1271.         Return SetError(1,0,-1)
  1272.     EndIf
  1273.     Local $objNodeList, $arrResponse[1], $objNodeChild, $xmlerr, $nodepath, $ns
  1274.     $objNodeList = $objDoc.selectNodes ($strXPath)
  1275.     If $objNodeList.length > 0 Then
  1276.         _DebugWrite("GetPath list length:" & $objNodeList.length)
  1277.         For $objNode In $objNodeList
  1278.             Local $objNode1 = $objNode
  1279.             $nodepath = ""
  1280.             $nodepathtag = ""
  1281.             If $objNode.nodeType <> $NODE_DOCUMENT Then
  1282.                 $ns = $objNode.namespaceURI ()
  1283.                 If $ns <> ""  Then
  1284.                     $ns = StringRight($ns, StringLen($ns) - StringInStr($ns, "/", 0, -1)) & ":"
  1285.                 EndIf
  1286.                 if $ns =0 then $ns =""
  1287.                 $nodepath = "/" & $ns & $objNode.nodeName () & $nodepath
  1288.             EndIf
  1289.             Do
  1290.                 $objParent = $objNode1.parentNode ()
  1291.                 _DebugWrite("parent " & $objParent.nodeName () & @LF)
  1292.                 If $objParent.nodeType <> $NODE_DOCUMENT Then
  1293.                     $ns = $objParent.namespaceURI ()
  1294.                     If $ns <> "" Then
  1295.                         ;$ns = StringRight($ns, StringLen($ns) - StringInStr($ns, "/", 0, -1)) & ":"
  1296.                         $ns &=":"
  1297.                     EndIf
  1298.                     if $ns =0 then $ns= ""
  1299.                     $nodepath = "/" &$ns  & $objParent.nodeName ()& $nodepath
  1300.                     $objNode1 = $objParent
  1301.                 Else
  1302.                     $objNode1 = 0
  1303.                 EndIf
  1304.                 $objParent = 0
  1305.             Until (Not (IsObj($objNode1)))
  1306.             _DebugWrite("Path node> " & $nodepath & @LF)
  1307.             _XMLArrayAdd($arrResponse, $nodepath)
  1308.         Next
  1309.         $arrResponse[0] = UBound($arrResponse) - 1
  1310.         Return $arrResponse
  1311.     EndIf
  1312.     $xmlerr = @CRLF & "No matching node(s)found!"
  1313.     _XMLError("Error Retrieving: " & $strXPath & $xmlerr)
  1314.     Return SetError(1,0,-1)
  1315. EndFunc   ;==>_XMLGetPath
  1316.  
  1317. ;===============================================================================
  1318. ; Function Name :   _XMLGetPathInternal
  1319. ; Description       :   Returns the path of a valid node object.
  1320. ; Parameter(s)      :   $objNode        A valid node object
  1321. ; Requirement(s)    :
  1322. ; Return Value(s)   :   A string path,  an empty string and set error on fail.
  1323. ; User CallTip      :
  1324. ; Author(s)         :   Stephen Podhajecki <gehossafats at netmdc.com/>
  1325. ; Note(s)           :
  1326. ;===============================================================================
  1327. Func _XMLGetPathInternal($objNode)
  1328.     If not IsObj($objDoc) then
  1329.         _XMLError("No object passed to function _XMLGetPathInternal")
  1330.         Return SetError(1,25,-1)
  1331.     EndIf
  1332.     Local $nodepath, $na, $objParent
  1333.     If IsObj($objNode) Then
  1334.         $nodepath = "/" & $objNode.baseName
  1335.         Do
  1336.             $objParent = $objNode.parentNode ()
  1337.             _DebugWrite("parent" & $objParent.nodeName () & ">" & @LF)
  1338.             If $objParent.nodeType <> $NODE_DOCUMENT Then
  1339.                 $ns = $objParent.namespaceURI ()
  1340.                 If $ns = 0 Then $ns = ""
  1341.                 If $ns <> "" Then
  1342.                     $ns = StringRight($ns, StringLen($ns) - StringInStr($ns, "/", 0, -1)) & ":"
  1343.                 EndIf
  1344.                 $nodepath = "/" & $ns & $objParent.nodeName () & $nodepath
  1345.                 $objNode = $objParent
  1346.             Else
  1347.                 $objNode = 0
  1348.             EndIf
  1349.             $objParent = 0
  1350.         Until (Not (IsObj($objNode)))
  1351.         _DebugWrite("Path node>" & $nodepath & @LF)
  1352.         Return ($nodepath)
  1353.     Else
  1354.         Return SetError(1, 0, "")
  1355.     EndIf
  1356. EndFunc   ;==>_XMLGetPathInternal
  1357. ;===============================================================================
  1358. ; Function Name: _XMLReplaceChild
  1359. ; Description: Replaces a node with another
  1360. ; Parameter(s): $oldNode Node to replace
  1361. ;                    $newNode The replacement node.
  1362. ; Syntax: _XMLReplaceChild(oldNode,newNode)
  1363. ; Author(s): Stephen Podhajecki <[email protected]> adapted from
  1364. ;                   http://www.perfectxml.com/msxmlAnswers.asp?Row_ID=65
  1365. ; Return Value(s)
  1366. ;===============================================================================
  1367. Func _XMLReplaceChild($objOldNode, $objNewNode, $ns = "")
  1368.     If not IsObj($objDoc) then
  1369.         _XMLError("No object passed to function _XMLReplaceChild")
  1370.         Return SetError(1,26,-1)
  1371.     EndIf
  1372.     If $objOldNode = "" Or $objNewNode = "" Then Return SetError(1)
  1373.     Local $nodeRoot
  1374.     Local $nodeOld
  1375.     Local $nodeNew
  1376.     Local $nodeTemp
  1377.     Local $bSuccess = False
  1378.     ;No error handling done
  1379.     With $objDoc
  1380.         ;;.Load "c:\books.xml"
  1381.         $nodeRoot = .documentElement
  1382.         $oldNodes = $nodeRoot.selectNodes ($objOldNode)
  1383.         ;'For each Node
  1384.         For $nodeOld In $oldNodes
  1385.             ;Create a New element
  1386.             $nodeNew = .createNode ($NODE_ELEMENT, $objNewNode, $ns)
  1387.             ;Copy attributes
  1388.             For $nodeTemp In $nodeOld.Attributes
  1389.                 $nodeNew.Attributes.setNamedItem ($nodeTemp.cloneNode (True))
  1390.             Next
  1391.             ;Copy Child Nodes
  1392.             For $nodeTemp In $nodeOld.childNodes
  1393.                 $nodeNew.appendChild ($nodeTemp)
  1394.             Next
  1395.             ;Replace with the renamed node
  1396.             If IsObj($nodeOld.parentNode.replaceChild ($nodeNew, $nodeOld)) Then $bSuccess = 1
  1397.             If Not ($objDoc.parseError.errorCode = 0) Then
  1398.                 _XMLError("_XMLReplaceChild:" & @LF & "Error Replacing Child: " & _
  1399.                         $objDoc.parseError.errorCode & _
  1400.                         " " & $objDoc.parseError.reason)
  1401.                 $bSucess = False
  1402.                 ExitLoop
  1403.             Else
  1404.                 $bSuccess = True
  1405.             EndIf
  1406.         Next
  1407.         .save ($strFile)
  1408.     EndWith
  1409.     $nodeRoot = 0
  1410.     $nodeOld = 0
  1411.     $nodeNew = 0
  1412.     $nodeTemp = 0
  1413.     Return $bSuccess
  1414. EndFunc   ;==>_XMLReplaceChild
  1415. ;===============================================================================
  1416. ; Function Name:    _XMLSchemaValidate
  1417. ; Description:      Validates a document against a dtd.
  1418. ; Parameter(s): $sXMLFile   The file to validate
  1419. ;                       $ns  xml namespace
  1420. ;                       $sXSDFile   DTD file to validate against.
  1421. ; Syntax:           _XMLSchemaValidate($sXMLFile, $ns, $sXSDFile)
  1422. ; Author(s):        Stephen Podhajecki <[email protected]>
  1423. ; Return Value(s)           1 on success or SetError(errorcode) on failure
  1424. ;===============================================================================
  1425. Func _XMLSchemaValidate($sXMLFile, $ns, $sXSDFile)
  1426. ;~  If not IsObj($objDoc) then
  1427. ;~      _XMLError("No object passed to function _XMLSchemaValidate")
  1428. ;~      Return SetError(1,27,-1)
  1429. ;~  EndIf
  1430.     Local $cache, $xmldoc
  1431.     $cache = ObjCreate("Msxml2.XMLSchemaCache." & $DOMVERSION & ".0")
  1432.     If Not IsObj($cache) Then
  1433.         MsgBox(266288, "XML Error", "Unable to instantiate the XML object" & @LF & "Please check your components.")
  1434.         Return SetError(-1)
  1435.     EndIf
  1436.     $cache.add ($ns, $sXSDFile)
  1437.     $xmldoc = ObjCreate("Msxml2.DOMDocument." & $DOMVERSION & ".0")
  1438.     If Not IsObj($xmldoc) Then
  1439.         MsgBox(266288, "XML Error", "Unable to instantiate the XML object" & @LF & "Please check your components.")
  1440.         Return SetError(-1)
  1441.     EndIf
  1442.     $xmldoc.async = False
  1443.     $xmldoc.schemas = $cache
  1444.     $xmldoc.load ($sXMLFile)
  1445.     If Not ($xmldoc.parseError.errorCode = 0) Then
  1446.         _XMLError("_XMLSchemaValidate:" & @LF & "Error: " & $xmldoc.parseError.errorCode & " " & $xmldoc.parseError.reason)
  1447.         Return SetError($xmldoc.parseError.errorCode)
  1448.     EndIf
  1449.     Return 0
  1450. EndFunc   ;==>_XMLSchemaValidate
  1451. ;===============================================================================
  1452. ; Function Name:    _XMLGetDomVersion
  1453. ; Description:      Returns the version of msxml that is in use for the document.
  1454. ;
  1455. ; Syntax:           _XMLGetDomVersion()
  1456. ; Author(s):        Stephen Podhajecki <[email protected]>
  1457. ; Return Value(s)           msxml version or -1
  1458. ;===============================================================================
  1459. Func _XMLGetDomVersion()
  1460.     Return $DOMVERSION
  1461. EndFunc   ;==>_XMLGetDomVersion
  1462. ;===============================================================================
  1463. ; Function Name:    _XMLError
  1464. ; Description:      Sets error message generated by XML functs.
  1465. ;                   or Gets the message that was Set.
  1466. ; Parameter(s):     $sError Node from root to delete
  1467. ; Syntax:           _XMLError([$sError)
  1468. ; Author(s):        Stephen Podhajecki <[email protected]>
  1469. ; Return Value(s)           Nothing or Error message
  1470. ;===============================================================================
  1471. Func _XMLError($sError = "")
  1472.     If $sError = "" Then
  1473.         $sError = $sXML_error
  1474.         $sXML_error = ""
  1475.         Return $sError
  1476.     Else
  1477.         $sXML_error = StringFormat($sError)
  1478.     EndIf
  1479.     _DebugWrite($sXML_error)
  1480. EndFunc   ;==>_XMLError
  1481. ;===============================================================================
  1482. ; Function Name:    _XMLCOMEerr
  1483. ; Description:      Displays a message box with the COM Error.
  1484. ; Parameter(s):     none
  1485. ; Syntax:           _XMLCOMEerr()
  1486. ; Author(s):        SvenP 's error handler
  1487. ; Return Value(s)
  1488. ; From the forum this came.
  1489. ;===============================================================================
  1490. Func _XMLCOMEerr()
  1491.     _ComErrorHandler()
  1492.     Return
  1493. EndFunc   ;==>_XMLCOMEerr
  1494. Func _ComErrorHandler($quiet = "")
  1495.     Local $COMErr_Silent, $HexNumber
  1496.     ;===============================================================================
  1497.     ;added silent switch to allow the func returned to the option to display custom
  1498.     ;error messages
  1499.     If $quiet = True Or $quiet = False Then
  1500.         $COMErr_Silent = $quiet
  1501.         $quiet = ""
  1502.     EndIf
  1503.     ;===============================================================================
  1504.     $HexNumber = Hex($oXMLMyError.number, 8)
  1505.     If @error Then Return
  1506.     Local $msg = "COM Error with DOM!" & @CRLF & @CRLF & _
  1507.             "err.description is: " & @TAB & $oXMLMyError.description & @CRLF & _
  1508.             "err.windescription:" & @TAB & $oXMLMyError.windescription & @CRLF & _
  1509.             "err.number is: " & @TAB & $HexNumber & @CRLF & _
  1510.             "err.lastdllerror is: " & @TAB & $oXMLMyError.lastdllerror & @CRLF & _
  1511.             "err.scriptline is: " & @TAB & $oXMLMyError.scriptline & @CRLF & _
  1512.             "err.source is: " & @TAB & $oXMLMyError.source & @CRLF & _
  1513.             "err.helpfile is: " & @TAB & $oXMLMyError.helpfile & @CRLF & _
  1514.             "err.helpcontext is: " & @TAB & $oXMLMyError.helpcontext
  1515.     If $COMErr_Silent <> True Then
  1516.         ;MsgBox(0, @AutoItExe, $msg)
  1517.     Else
  1518.         _XMLError($msg)
  1519.     EndIf
  1520.     SetError(1)
  1521. EndFunc   ;==>_ComErrorHandler
  1522. ; simple helper functions
  1523. ;===============================================================================
  1524. ; Function Name:    -   _DebugWrite($message)
  1525. ; Description:      - Writes a message to console with a crlf on the end
  1526. ; Parameter(s):     - $message the message to display
  1527. ; Syntax:           - _DebugWrite($message)
  1528. ; Author(s):        -
  1529. ; Return Value(s)           -
  1530. ;===============================================================================
  1531. Func _DebugWrite($message, $flag = @LF)
  1532.     If $debugging Then
  1533.         ConsoleWrite(StringFormat($message)&$flag)
  1534.     EndIf
  1535. EndFunc   ;==>_DebugWrite
  1536. ;===============================================================================
  1537. ; Function Name:    _Notifier($Notifier_msg)
  1538. ; Description:      displays a simple "ok" messagebox
  1539. ; Parameter(s):     $Notifier_Msg The message to display
  1540. ; Syntax:           _Notifier($Notifier_msg)
  1541. ; Author(s):        -
  1542. ; Return Value(s)           -
  1543. ;===============================================================================
  1544. Func _Notifier($Notifier_msg)
  1545.     Return MsgBox(266288, @ScriptName, $Notifier_msg)
  1546. EndFunc   ;==>_Notifier
  1547. ;===============================================================================
  1548. ; Function Name:    -   _SetDebug($flag =False)
  1549. ; Description:      - Writes a message to console with a crlf on the end
  1550. ; Parameter(s):     - $message the message to display
  1551. ; Syntax:           - _DebugWrite($message)
  1552. ; Author(s):        -
  1553. ; Return Value(s)           -
  1554. ;===============================================================================
  1555. Func _SetDebug($debug_flag = True)
  1556.     $debugging = $debug_flag
  1557.     ConsoleWrite("Debug = " & $debugging & @LF)
  1558. EndFunc   ;==>_SetDebug
  1559. ;===============================================================================
  1560. ; Function Name:    _XMLUDFVersion()
  1561. ; Description:      Returns UDF version number
  1562. ; Parameter(s): None
  1563. ; Syntax:           _XMLUDFVersion()
  1564. ; Author(s):        Stephen Podhajecki
  1565. ; Return Value(s)   UDF version number
  1566. ;===============================================================================
  1567. Func _XMLUDFVersion()
  1568.     Return $_XMLUDFVER
  1569. EndFunc   ;==>_XMLUDFVersion
  1570. ;===============================================================================
  1571. ; Function Name:    _XMLTransform
  1572. ; Description:
  1573. ; Parameter(s): $oXMLDoc        The document to transform
  1574. ;                       $Style      (optional) The stylesheet to use
  1575. ;                       $szNewDoc   (optional) Save to this file.
  1576. ; Return Value(s):  On Success returns 1
  1577. ;                           On Failure @Error = 1
  1578. ; User CallTip:
  1579. ; Author(s):        Stephen Podhajecki <gehossafats at netmdc dot com>
  1580. ; Note(s):
  1581. ;===============================================================================
  1582. Func _XMLTransform($oXMLDoc="", $Style = "", $szNewDoc = "")
  1583.     If $oXMLDoc = "" Then
  1584.         $oXMLDoc = $objDoc
  1585.     EndIf
  1586.     If not IsObj($oXMLDoc) then
  1587.         _XMLError("No object passed to function _XMLSetAttrib")
  1588.         Return SetError(1,29,-1)
  1589.     EndIf
  1590.     Local $bIndented = False
  1591.     Local $xslt = ObjCreate("MSXML2.XSLTemplate." & $DOMVERSION & ".0")
  1592.     Local $xslDoc = ObjCreate("MSXML2.FreeThreadedDOMDocument." & $DOMVERSION & ".0")
  1593.     Local $xmldoc = ObjCreate("MSXML2.DOMDocument." & $DOMVERSION & ".0")
  1594.     Local $xslProc
  1595.     $xslDoc.async = False
  1596.     If FileExists($Style) Then
  1597.         _DebugWrite("LoadXML:1:" & $xslDoc.load ($Style) & @LF)
  1598.     Else
  1599.         _DebugWrite("LoadXML:2:" & $xslDoc.loadXML (_GetDefaultStyleSheet()) & @LF)
  1600.     EndIf
  1601.     If $xslDoc.parseError.errorCode <> 0 Then
  1602.         _XMLError("Error Transforming NodeToObject: " & $xslDoc.parseError.reason)
  1603.     EndIf
  1604.     If Not FileExists("XSLFile.xsl") Then FileWrite("XSLFile.xsl", $xslDoc.xml ())
  1605.     $xslt.stylesheet = $xslDoc
  1606.     $xslProc = $xslt.createProcessor ()
  1607.     $xslProc.input = $objDoc
  1608.     $oXMLDoc.transformNodeToObject ($xslDoc, $xmldoc)
  1609.     If $oXMLDoc.parseError.errorCode <> 0 Then
  1610.         _XMLError("_XMLTransform:" & @LF & "Error Transforming NodeToObject: " & $oXMLDoc.parseError.reason)
  1611.         $bIndented = False
  1612.     Else
  1613.         $bIndented = True
  1614.     EndIf
  1615.     If $bIndented Then
  1616.         If $szNewDoc <> "" Then
  1617.             $xmldoc.save ($szNewDoc)
  1618.             If $xmldoc.parseError.errorCode <> 0 Then
  1619.                 _XMLError("_XMLTransform:" & @LF & "Error Saving: " & $xmldoc.parseError.reason)
  1620.                 $bIndented = False
  1621.             EndIf
  1622.         Else
  1623.             $xmldoc.save ($strFile)
  1624.             $oXMLDoc.Load ($strFile)
  1625.             If $oXMLDoc.parseError.errorCode <> 0 Then
  1626.                 _XMLError("_XMLTransform:" & @LF & "Error Saving: " & $oXMLDoc.parseError.reason)
  1627.                 $bIndented = False
  1628.             EndIf
  1629.         EndIf
  1630.     EndIf
  1631.     $xslProc = 0
  1632.     $xslt = 0
  1633.     $xslDoc = 0
  1634.     $xmldoc = 0
  1635.     Return $bIndented
  1636. EndFunc   ;==>_XMLTransform
  1637. ;===============================================================================
  1638. ; Function Name:    _GetDefaultStyleSheet
  1639. ; Description:   Internal function, returns the default indenting style sheet
  1640. ; Parameter(s): Requirement(s):
  1641. ; Return Value(s): Stylesheet on success for nothing on failure.
  1642. ; User CallTip:
  1643. ; Author(s):
  1644. ; Note(s):
  1645. ;===============================================================================
  1646. Func _GetDefaultStyleSheet()
  1647.     Return '<?xml version="1.0" encoding="ISO-8859-1"?>' & _
  1648.             '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">' & _
  1649.             '<xsl:output method="xml" indent="yes"/> ' & _
  1650.             '<xsl:template match="*">' & _
  1651.             '<xsl:copy>' & _
  1652.             '<xsl:copy-of select="@*" />' & _
  1653.             '<xsl:apply-templates />' & _
  1654.             '</xsl:copy>' & _
  1655.             '</xsl:template>' & _
  1656.             '<xsl:template match="comment()|processing-instruction()">' & _
  1657.             '<xsl:copy />' & _
  1658.             '</xsl:template>' & _
  1659.             '</xsl:stylesheet>'
  1660. EndFunc   ;==>_GetDefaultStyleSheet
  1661. ;===============================================================================
  1662. ; Function Name:    _AddFormat
  1663. ; Description:
  1664. ; Parameter(s): $objDoc  Document to format
  1665. ;                       $objParent   Optional node to add formatting to
  1666. ; Requirement(s):
  1667. ; Return Value(s):
  1668. ; User CallTip:
  1669. ; Author(s):        Stephen Podhajecki <gehossafats a t netmdc.com>
  1670. ; Note(s):          just break up the tags, no indenting is done here.
  1671. ;===============================================================================
  1672. Func _AddFormat($objDoc, $objParent = "")
  1673.     If not IsObj($objDoc) then
  1674.         _XMLError("No object passed to function _XMLAddFormat")
  1675.         Return SetError(1,30,-1)
  1676.     EndIf
  1677.     $objFormat = $objDoc.createTextNode (@CR)
  1678.     If IsObj($objParent) Then
  1679.         $objParent.appendChild ($objFormat)
  1680.     Else
  1681.         $objDoc.documentElement.appendChild ($objFormat)
  1682.     EndIf
  1683.             If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
  1684. EndFunc   ;==>_AddFormat
  1685. ;===============================================================================
  1686. ; Function Name:    _XMLSetAutoSave
  1687. ; Description:      Set the forced save to on or off
  1688. ; Parameter(s): $bSave
  1689. ; Requirement(s):
  1690. ; Return Value(s): previous state
  1691. ; User CallTip:
  1692. ; Author(s):        Stephen Podhajecki <gehossafats a t netmdc.com>
  1693. ; Note(s):          Defaults to true.
  1694. ;===============================================================================
  1695. Func _XMLSetAutoSave($bSave = True)
  1696.     Local $oldSave = $bXMLAUTOSAVE
  1697.     if $bSave = False Then
  1698.         $bXMLAUTOSAVE = True
  1699.     Else
  1700.         $bXMLAUTOSAVE = False
  1701.     EndIf
  1702.     Return $oldSave
  1703. EndFunc
  1704. ;===============================================================================
  1705. ; Function Name:    _XMLSaveDoc
  1706. ; Description:      Save the current xml doc
  1707. ; Parameter(s): $sFile - The filename to save the xml doc as.
  1708. ; Requirement(s):
  1709. ; Return Value(s): none
  1710. ; User CallTip:
  1711. ; Author(s):        Stephen Podhajecki <gehossafats a t netmdc.com>
  1712. ; Note(s):          Defaults to the current filename.
  1713. ;===============================================================================
  1714. Func _XMLSaveDoc($sFile="")
  1715.     if $sFile = "" Then $sFile = $strFile
  1716.     $objDoc.save($sFile)
  1717. EndFunc
  1718.  
  1719. ;===============================================================================
  1720. ; Function Name:    _XMLNodeExists
  1721. ; Description:      Checks for the existence of a node or nodes matching the specified path
  1722. ; Parameter(s): $strXPath - Path to check for.
  1723. ; Requirement(s):
  1724. ; Return Value(s): 1 or Higher on success, 0 on failure
  1725. ;                       @Error set to
  1726. ;                           0 no error
  1727. ;                           1 No XML object @extended = 31
  1728. ;                           2 Node not found
  1729. ; User CallTip:
  1730. ; Author(s):        Stephen Podhajecki <gehossafats a t netmdc.com>
  1731. ; Note(s):          Returns the number of nodes found (could be greater than 1)
  1732. ;===============================================================================
  1733. Func _XMLNodeExists($strXPath)
  1734.     If not IsObj($objDoc) then
  1735.         _XMLError("No object passed to function _XMLNodeExists")
  1736.         Return SetError(1,31,0)
  1737.     EndIf
  1738.     Local $objNode, $iCount
  1739.     Local $objNode =  $objDoc.SelectNodes($strXPath)
  1740.     If IsObj($objNode) Then $iCount = $objNode.length
  1741.     $objNode = 0
  1742.     if $iCount Then Return $iCount
  1743.     Return SetError(2,0,0)
  1744. EndFunc
  1745. ; =======================================================================
  1746. ; Preprocessed included functions...
  1747. ; =======================================================================
  1748. Func _XMLArrayAdd(ByRef $avArray, $sValue)
  1749.     If IsArray($avArray) Then
  1750.         ReDim $avArray[UBound($avArray) + 1]
  1751.         $avArray[UBound($avArray) - 1] = $sValue
  1752.         SetError(0)
  1753.         Return 1
  1754.     Else
  1755.         SetError(1)
  1756.         Return 0
  1757.     EndIf
  1758. EndFunc   ;==>_XMLArrayAdd
Advertisement
Add Comment
Please, Sign In to add comment