Solved

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

Posted on 2009-05-08
13
381 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide vba in gp 7 93
how to update exe applicatio from internet ? 6 76
Arduino EDI - Programming Language - Voice Recorder 4 81
Regular Expression Calculator Tester 2 71
A short article about a problem I had getting the GPS LocationListener working.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now