2

I want to save an RSS feed to an xml document on my computer. I'm using XPath with Java to parse the XML myself, so all I want is a file that contains the source (XML) I see when I view the source of the website's RSS page.

In other words, instead of copying and pasting the source of the RSS page into a file I save as an XML file, I'd like to write a program that pulls this for me.

2 Answers 2

5

You don't even need to introduce a library to do that!

Simply get an URL-object on the Rss-Feed you want to "download" and use the openConnection()-method to get an URLConnection.

You can then use it's getInputStream()-method. From this InputStream you can read the unparsed source of the RSS document (you should wrapp it with a BufferedInputStream).

This can then be saved as a String (in memory) or directly written to the HDD by using a FileOutputStream.


An example-implementation can be found here: https://gist.github.com/2320294

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! This is totally right-on, I've got it working. I also referenced this site for help with the writing of the file (I did not realize I had to make a byte array and feed bytes to write()): mkyong.com/java/how-to-convert-inputstream-to-file-in-java
@blaughli you don't have to do this! You should use a BufferedOutputStream on the FileOutputStream. Then, you can simply feed it strings. The example shows how to implement a buffer (at least the idea) and that's not what you need. I'll put up some example code when I have Java running on this machine.
@blaughli I included an example of how this can be done (without manual buffering using byte-arrays) in the post. Check it out!
0

You can use Apache commons HttpClient to get the file from the web. The usage of this library is very convenient. Here's the official tutorial.

2 Comments

Thanks, I ended up not using the Apache Library but I did explore it and it may come in handy in the future. Good to know it's there for all HTTP issues!
Great :) I believe it will become handy one day (it did for me)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.