sapper1971 Posted July 31, 2011 Posted July 31, 2011 marketprices.xml Hi I have been struggling to get this piece of code to work, it works fine if the xml file only has one record on it but if multiple records are returned it sends back the correct code to the console. If Multiple records exist then it returns the first record ok and the first nodes of the rest of the records are also returned ok but the next node down returns a -1 error. I have tried to work this out on my own using examples but I cant seem to sort it out, I'm new to autoit and would appreciate a guiding hand I don't expect you to do it all for me but a nudge in the right direction would be a great help Thanks in advance. Please ignore any globals that are mentioned but not used as this is part of a larger script but this will be turned into a function so for now im using this part as a standalone script until the data returned in the console is correct I will then adjust it accordingly. Thankyou. expandcollapse popup#NoTrayIcon #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <IE.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <GUIConstants.au3> #include <GDIPlus.au3> #include <String.au3> #Include <WinAPI.au3> #include <array.au3> #include <Misc.au3> #include <IE.au3> #include <HTTP.au3> #include <File.au3> #include <GuiTab.au3> #include <Array.au3> #include <_XMLDOMWrapper.au3> Global $sMyXML, $iRET, $iPitch, $sID, $sSCN, $sCC, $iBPQ, $iBPL, $iBPAI, $iSPQ, $iSPL, $iSPAI, $oIE ; Load XML $sMyXML = @ScriptDir & "\marketprices.xml" $iRET = _XMLFileOpen($sMyXML) If @error Or $iRET <> 1 Then ConsoleWrite("Error: Failed to load XML document: " & $sMyXML & @LF) Exit EndIf $iPitch = _XMLGetNodeCount("/envelope/message/market/pitches/pitch") ConsoleWrite("Records = " & $iPitch & @LF) For $a = 1 To $iPitch $sSCN = _XMLGetAttrib("/envelope/message/market/pitches/pitch[" & $a & "]", "securityClassNarrative") $sID = _XMLGetAttrib("/envelope/message/market/pitches/pitch[" & $a & "]", "securityId") $sCC = _XMLGetAttrib("/envelope/message/market/pitches/pitch[" & $a & "]", "considerationCurrency") $iBPQ = _XMLGetAttrib("/envelope/message/market/pitches/pitch/buyPrices/price[" & $a & "]", "quantity") $iBPL = _XMLGetAttrib("/envelope/message/market/pitches/pitch/buyPrices/price[" & $a & "]", "limit") $iBPAI = _XMLGetAttrib("/envelope/message/market/pitches/pitch/buyPrices/price[" & $a & "]", "actionIndicator") ConsoleWrite("Metal = " & $sSCN & @LF) ConsoleWrite("Location = " & $sID & @LF) ConsoleWrite("Currency = " & $sCC & @LF) ConsoleWrite("Quantity = " & $iBPQ & @LF) ConsoleWrite("Price = " & $iBPL & @LF) ConsoleWrite("Buy or Sell = " & $iBPAI & @LF) next
ProgAndy Posted July 31, 2011 Posted July 31, 2011 (edited) I have to admit, I don't like the xmldomwrapper-udf. I prefer accessing the object directly: $o = ObjCreate("Msxml2.DOMDocument") ;~ $s = FileRead(@TempDir & "\marketprices.xml") ;~ $o.loadXML($s) $o.load(@TempDir & "\marketprices.xml") $o.setProperty("SelectionLanguage", "XPath") $oPitches = $o.selectNodes("//envelope/message/market/pitches/pitch") For $oPitch In $oPitches $oBuyPrice = $oPitch.selectSingleNode("buyPrices/price") $scn = _NodeGetValue($oPitch.attributes.getNamedItem("securityClassNarrative")) $sid = _NodeGetValue($oPitch.attributes.getNamedItem("securityId")) $quant = _NodeGetValue($oBuyPrice.attributes.getNamedItem("quantity")) $limit = _NodeGetValue($oBuyPrice.attributes.getNamedItem("limit")) ConsoleWrite($scn & " - " & $sid & " - " & $quant & " - " & $limit & @CRLF) Next Func _NodeGetValue(Const $oNode, $vDefault = "") If Not IsObj($oNode) Then Return SetError(1, 0, $vDefault) Return $oNode.value EndFunc The documentation can be found here: http://msdn.microsoft.com/en-us/library/ms766487%28VS.85%29.aspx Edited July 31, 2011 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
sapper1971 Posted August 1, 2011 Author Posted August 1, 2011 Thanks for your reply it's appreciated, I will give it a go and see how it goes I do have other nodes to deal with but no doubt your example gives me the starting block to work out the rest thankyou very much... Paul..
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