iceberg Posted January 17, 2010 Share Posted January 17, 2010 hi everyone, i have attached a sample XML file. i need to download the exe files only for the GroupName="Windows". The exe files are in between the <DownloadURL> & </DownloadURL>. how can I achieve this? thank you.server.xml mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
Bowmore Posted January 17, 2010 Share Posted January 17, 2010 This sounds like an ideal use for the _StringBetween() function. Check the help file for details and an example. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
iceberg Posted January 22, 2010 Author Share Posted January 22, 2010 tried that function but its too messy and tedious. can someone tell me how i can use it with _xmldomwrapper? thanks. mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
Bowmore Posted January 23, 2010 Share Posted January 23, 2010 (edited) tried that function but its too messy and tedious. can someone tell me how i can use it with _xmldomwrapper? thanks. This example uses _StringBetween() which for this particular task I think is simpler than using _xmldomwrapper although _xmldomwrapper is the way to go if you want to do more complex things with XML files. #include <string.au3> $XMLData = FileRead("C:\Documents and Settings\Roy Kirby\My Documents\server.xml") ;Remove any pretty formatting $XMLData = StringRegExpReplace($XMLData,">[\s\n\r]*<", "><") ;Create an array of URLs to be downloaded $aFilesToDownload = _StringBetween($XMLData,"<DownloadURL>","</DownloadURL>") For $i = 0 To UBound($aFilesToDownload) - 1 ;Build a local filename $aFile = StringRegExp($aFilesToDownload[$i],"[^/]+$",3) $sLocalFile = "C:\Downloads\" & $aFile[0] ;Start download $hDownload = InetGet ($aFilesToDownload[$i] ,$sLocalFile , 8, 1) ;Wait for download to complete Do Sleep(250) Until InetGetInfo($hDownload, 2) ; Check if the download is complete. $nBytes = InetGetInfo($hDownload, 0) InetClose($hDownload) ; Close the handle to release resourcs. ;Just to show file has completed MsgBox(0, "Downloaded", $sLocalFile & @CRLF & "Bytes read: " & $nBytes) Next Edited January 23, 2010 by Bowmore "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 23, 2010 Share Posted January 23, 2010 You mean like this? #include <Array.au3> #include <_XMLDOMWrapper.au3> $sXML = @ScriptDir & "\Test1.xml" $iRET = _XMLFileOpen($sXML) If @error Or $iRET <> 1 Then ConsoleWrite("Error: Failed to open XML correctly: $iRET = " & $iRET & "; @error = " & @error & @LF) Exit EndIf $iCnt = _XMLGetNodeCount("/XMLOut/Check[@GroupName='Windows']/Detail/UpdateData/References/DownloadURL") ConsoleWrite("Debug: $iCnt = " & $iCnt & "; @error = " & @error & "; @extended = " & @extended & @LF) $aDownloadURLs = _XmlGetValue("/XMLOut/Check[@GroupName='Windows']/Detail/UpdateData/References/DownloadURL") ConsoleWrite("Debug: @error = " & @error & "; @extended = " & @extended & @LF) If IsArray($aDownloadURLs) Then _ArrayDisplay($aDownloadURLs, "Download URLs") I needed the exercise... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
iceberg Posted January 25, 2010 Author Share Posted January 25, 2010 bowmore > thanks! your codes work fine on the whole. But I only wanna download the URLS from the Windows group. your codes download from the entried XML files. PsaltyDS > Your codes works great! but i have 2 queries. hope you can enlighten me. 1) when the download URL array is displayed out, why is there the "the total number of downloads" in the row(0)? 2) i have figured out that I can play around with the group name filtering using an ini file. eg of my ini file [filter] groupname=Windows :eof and then i can modify my scipt using this : $var = IniRead("myfile.ini", "filter", "groupname", "NotFound") $iCnt = _XMLGetNodeCount("/XMLOut/Check[@GroupName=' & $var & ']/Detail/UpdateData/References/DownloadURL") ConsoleWrite("Debug: $iCnt = " & $iCnt & "; @error = " & @error & "; @extended = " & @extended & @LF) $aDownloadURLs = _XmlGetValue("/XMLOut/Check[@GroupName=' & var & ']/Detail/UpdateData/References/DownloadURL") what if I have an addition to the ini file where it looks like this [exe] 1=ie8 2=ie7 3=xml 4=media 5=sp1 6=sp2 7=sp3 and so on.....this entry is unlimited. how do i ensure that the downloadable URL does not contain any of the [exe] listed. it works with StringInStr. but how do i get it to work will all the unpredictable entries in the ini file? mine only works for the first one. thank you. mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 25, 2010 Share Posted January 25, 2010 1) when the download URL array is displayed out, why is there the "the total number of downloads" in the row(0)?Because _XMLGetValue() was written that way. If you don't like it, modify the function in your copy of the UDF or strip that element off with _ArrayDelete().2) i have figured out that I can play around with the group name filtering using an ini file. eg of my ini file...Lost track of the question while trying to figure out what you were talking about. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Bowmore Posted January 25, 2010 Share Posted January 25, 2010 @iceberg Sorry I missed the bit in your original post about only wanting the windows group updates. Modified to only download where Groupname = "Windows" [autoit] #include <string.au3> $XMLData = FileRead("C:\Documents and Settings\Roy Kirby\My Documents\server.xml") ;Remove any pretty formatting $XMLData = StringRegExpReplace($XMLData,">[\s\n\r]*<", "><") $aWindowGroup = _StringBetween($XMLData,'GroupName="Windows">','</Check>') If IsArray($aWindowGroup) Then $aFilesToDownload = _StringBetween($aWindowGroup[0],'<DownloadURL>','</DownloadURL>') For $i = 0 To UBound($aFilesToDownload) - 1 $aFile = StringRegExp($aFilesToDownload[$i],"[^/]+$",3) $sLocalFile = "C:\Downloads\" & $aFile[0] ;Start download $hDownload = InetGet ( $aFilesToDownload[$i] ,$sLocalFile , 8, 1) ;Wait for download to complete Do Sleep(250) Until InetGetInfo($hDownload, 2) ; Check if the download is complete. Local $nBytes = InetGetInfo($hDownload, 0) InetClose($hDownload) ; Close the handle to release resourcs. ;Just to show file has completed MsgBox(0, "Downloaded", $sLocalFile & @CRLF & "Bytes read: " & $nBytes) Next Else MsgBox(0,"Updates", "No updates for windows") EndIf [/auoit] "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
iceberg Posted January 26, 2010 Author Share Posted January 26, 2010 (edited) thanks for the clarificatio PsaltyDS. Bowmore, thanks for the codes. it works well now! please help me here for 1 last request. i need to further filter the downloads whereby 'IsInstalled="false"' then to download the file. thanks. Edited January 26, 2010 by iceberg mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 26, 2010 Share Posted January 26, 2010 i need to further filter the downloads whereby 'IsInstalled="false"' then to download the file.You've picked up enough to figure that out yourself. Check out this XPath tutorial (I love the W3Schools site) and look closely at the XPath examples you already have. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
iceberg Posted January 27, 2010 Author Share Posted January 27, 2010 yeah thanks for the link! i got it now. $iCnt = _XMLGetNodeCount("/XMLOut/Check[@GroupName='Windows']/Detail/UpdateData[@IsInstalled='false']/References/DownloadURL") thanks for all your help! mouse not found....scroll any mouse to continue. 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