Jump to content
Sign in to follow this  
iceberg

XML file

Recommended Posts

iceberg

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.

Share this post


Link to post
Share on other sites
Bowmore

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

Share this post


Link to post
Share on other sites
iceberg

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.

Share this post


Link to post
Share on other sites
Bowmore

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 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

Share this post


Link to post
Share on other sites
PsaltyDS

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... :D


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

Share this post


Link to post
Share on other sites
iceberg

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. :D

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.

Share this post


Link to post
Share on other sites
PsaltyDS

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.

:D


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

Share this post


Link to post
Share on other sites
Bowmore

@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

Share this post


Link to post
Share on other sites
iceberg

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 by iceberg

mouse not found....scroll any mouse to continue.

Share this post


Link to post
Share on other sites
PsaltyDS

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.

:D


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

Share this post


Link to post
Share on other sites
iceberg

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.

Share this post


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
Sign in to follow this  

×