Jump to content

XML DOM Wraper Help Please

Recommended Posts

I need some help. When I use the following code to get the value of "SpellID" in an xml database, I try writing to the same line, but it ends up writing to every single Node when I only want it to write to one single one.

For $X = 1 to $NodesArray[0]
        $CheckKey = CheckKey(_XMLGetAttrib($path & "/Key[" & $X & "]", "SpellID"))
        If $CheckKey = -1 Then
            MsgBox(16, "Error", "Unable to read process memory!")
        If $Bar <> "" Then
        $GetStatus = StringSplit($Bar, "|")
        If $GetStatus[0] = 2 Then
            _XMLSetAttrib($path & "/Key[@SpellID="&_XMLGetAttrib($path & "/Key[" & $X & "]", "SpellID")&"]", "BarState", $GetStatus[1])
            _XMLSetAttrib($path & "/Key[@SpellID="&_XMLGetAttrib($path & "/Key[" & $X & "]", "SpellID")&"]", "Char", $GetStatus[2])


Obviously there is something wrong with my _XMLSetAttrib() function

(Copied and pasted from my post on the XML DOM Wrapper forum, still seeking help please ^^:


Link to post
Share on other sites

i have limited knowlege of this library and XML but if you look at the source for the set attribute function-

; Function Name:    _XMLSetAttrib
; Description:      Set XML Field(s) based on XPath input from root node.
; Parameter(s):     $path xml tree path from root node (root/child/child..)
;                   $attrib the attribute to set.
;                   $value the value to give the attribute defaults to ""
; Syntax:           _XMLSetAttrib($path,$attrib,$value)
; Author(s):        Stephen Podhajecki <gehossafats@netmdc.com> 
; Return Value(s)           array of fields text values
;                   on error returns -1 and sets error to 1
Func _XMLSetAttrib($strXPath, $strAttrib, $strValue = "", $iIndex =-1)
    If not IsObj($objDoc) then
        _XMLError("No object passed to function _XMLSetAttrib")
        Return SetError(1,8,-1)
    Local $objNodeList, $arrResponse[1], $i
    $objNodeList = $objDoc.selectNodes ($strXPath)
    _DebugWrite(" Node list Length: " & $objNodeList.length)
    If @error = 0 And $objNodeList.length > 0 Then
        If $iIndex > 0 Then
            $arrResponse[0] = $objNodeList.item ($iIndex).SetAttribute ($strAttrib, $strValue)
            ReDim $arrResponse[$objNodeList.length]
            For $i = 0 To $objNodeList.length - 1
                $arrResponse[$i] = $objNodeList.item ($i).SetAttribute ($strAttrib, $strValue)
                If $objDoc.parseError.errorCode <> 0 Then ExitLoop
        If $objDoc.parseError.errorCode <> 0 Then
            _XMLError("Error setting attribute for: " & $strXPath & @CRLF & $objDoc.parseError.reason)
            Return SetError(1,$objDoc.parseError.errorCode,-1)
        If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile)
        Return $arrResponse
    _XMLError("Error failed to set attribute for: " & $strXPath & @CRLF)
    Return -1
EndFunc   ;==>_XMLSetAttrib

You can see it intentionally loops though each node-

For $i = 0 To $objNodeList.length - 1
    $arrResponse[$i] = $objNodeList.item ($i).SetAttribute ($strAttrib, $strValue)
    If $objDoc.parseError.errorCode <> 0 Then ExitLoop

and set's the attribute.

Im not so sure that's a bug becuase it seems to be designed behavior...but if you dont like it you could try making a custom version of the function yourself that suits your needs...

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...