=sinister= Posted February 20, 2008 Share Posted February 20, 2008 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!") ExitLoop EndIf 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]) EndIf EndIf NextObviously there is something wrong with my _XMLSetAttrib() function(Copied and pasted from my post on the XML DOM Wrapper forum, still seeking help please ^^:http://www.autoitscript.com/forum/index.php?showtopic=19848 Link to comment Share on other sites More sharing options...
evilertoaster Posted February 20, 2008 Share Posted February 20, 2008 i have limited knowlege of this library and XML but if you look at the source for the set attribute function- expandcollapse popup;=============================================================================== ; Function Name: _XMLSetAttrib ; Description: Set XML Field(s) based on XPath input from root node. ; Parameter(s): $path xml tree path from root node (root/child/child..) ; $attrib the attribute to set. ; $value the value to give the attribute defaults to "" ; Syntax: _XMLSetAttrib($path,$attrib,$value) ; Author(s): Stephen Podhajecki <gehossafats@netmdc.com> ; Return Value(s) array of fields text values ; on error returns -1 and sets error to 1 ;=============================================================================== Func _XMLSetAttrib($strXPath, $strAttrib, $strValue = "", $iIndex =-1) If not IsObj($objDoc) then _XMLError("No object passed to function _XMLSetAttrib") Return SetError(1,8,-1) EndIf Local $objNodeList, $arrResponse[1], $i $objNodeList = $objDoc.selectNodes ($strXPath) _DebugWrite(" Node list Length: " & $objNodeList.length) If @error = 0 And $objNodeList.length > 0 Then If $iIndex > 0 Then $arrResponse[0] = $objNodeList.item ($iIndex).SetAttribute ($strAttrib, $strValue) Else ReDim $arrResponse[$objNodeList.length] For $i = 0 To $objNodeList.length - 1 $arrResponse[$i] = $objNodeList.item ($i).SetAttribute ($strAttrib, $strValue) If $objDoc.parseError.errorCode <> 0 Then ExitLoop Next EndIf If $objDoc.parseError.errorCode <> 0 Then _XMLError("Error setting attribute for: " & $strXPath & @CRLF & $objDoc.parseError.reason) Return SetError(1,$objDoc.parseError.errorCode,-1) EndIf If ($bXMLAUTOSAVE = True) Then $objDoc.save ($strFile) Return $arrResponse EndIf _XMLError("Error failed to set attribute for: " & $strXPath & @CRLF) SetError(1) Return -1 EndFunc ;==>_XMLSetAttrib 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 Next 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 comment Share on other sites More sharing options...
=sinister= Posted February 21, 2008 Author Share Posted February 21, 2008 Ha that's gonna be hard for me seeing as how I don't know that much about xml and don't know much about he for loop either. Link to comment Share on other sites More sharing options...
weaponx Posted February 21, 2008 Share Posted February 21, 2008 This question looks familiar, oh right you already asked it. See the answer here:#482139 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now