Solved

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

Posted on 2009-05-08
13
398 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

751 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