Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-05-08
13
Medium Priority
?
413 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Simple Linear Regression
Loops Section Overview

916 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