Solved

How to download an XML file from a url and save it into local drive

Posted on 2009-05-08
13
395 Views
Last Modified: 2012-05-06
I need a simple script that downloads and xml from a web line and save it into the local drive.


Thank you in advance.



0
Comment
Question by:ABalfaqih
  • 5
  • 4
  • 3
13 Comments
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24342331
Hope this helps:

MsgBox getWebPage("http://www.google.com")


Function getWebPage(url)
      Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
      xmlhttp.open "get", url, False
      xmlhttp.send
      getWebPage = xmlhttp.responseText
End Function
0
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24342363
Just to make solution complete ... saveFile sub included.

x = getWebPage("http://www.google.com")
saveFile "C:\temp\test2.html", x

Function getWebPage(url)
      Set xmlhttp = CreateObject("msxml2.xmlhttp.3.0")
      xmlhttp.open "get", url, False
      xmlhttp.send
      getWebPage = xmlhttp.responseText
      Set xmlhttp = Nothing
End Function

Sub saveFile(fileName, content)
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set t = fso.OpenTextFile(fileName, 8, True)
    t.WriteLine (content)
    t.Close
    Set t = Nothing
    Set fso = Nothing
End Sub
0
 

Author Comment

by:ABalfaqih
ID: 24342460
Thank you for the quick reply.
I was thinking of downloading an xml file like this (http://thestar.com.my/rss/worldupdates.xml) into my local drive, and saved as an .xml file.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:SalmanZG
ID: 24342521
This will work fine - simply put your url as the parameter of the getWebPage function.

x = getWebPage("http://thestar.com.my/rss/worldupdates.xml")
0
 
LVL 2

Accepted Solution

by:
Nas-Banov earned 125 total points
ID: 24342717
Just open the URL (http://thestar.com.my/rss/worldupdates.xml) in a browser (IE or Firefox), right-click "View Source" and from there File / Save As... and select where to save the XML file.
0
 

Author Closing Comment

by:ABalfaqih
ID: 31579709
Great, it is a lot simple than I thought. Thanks.
0
 

Author Comment

by:ABalfaqih
ID: 24344038
Nas,

I needed the script as I pass the values of the url and path in the local drive using another software. It is not done manual.  
I already have another script that I wrote, but wanted to see a different way of doing it.


0
 
LVL 3

Expert Comment

by:SalmanZG
ID: 24344589
Hi ABalfaqih,
Does my solution satisfies your need? I was wondering about acceptance of solution without the script.
0
 
LVL 2

Expert Comment

by:Nas-Banov
ID: 24345398
It's unclear what kind of coding you are doing (server-side, client-side, batch etc). This can be written differently in different languages. For example, if you have Python installed, try the one below


import urllib
 
f = open ('somename.xml', 'w')
f.write(urllib.urlopen("http://yahoo.com").read())
f.close()

Open in new window

0
 

Author Comment

by:ABalfaqih
ID: 24346329
Salman code was what I wanted to see. And it workded. Nas suggestion was correct but I wanted the script as I was doing some sort of client based application. I have another script that manipulates further the XML.

As of the Python code, I am impressed with so few lines you could do the same. Just to confirm, does it include the saving of the file too?
0
 
LVL 2

Expert Comment

by:Nas-Banov
ID: 24346539
yes, the python snippet includes the url reading and file writing
0
 

Author Comment

by:ABalfaqih
ID: 24346647
Nas,

I am impressed.You got me interested in Python... it must be one hell of a language. Thanks.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question