![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Sexy Programmer
|
Starting an RSS Reader
I am in the planning process of my RSS Reader project. I am creating an RSS Reader because I want to exercise my Java skills for the end of the summer and create something that maybe people who actually use besides a stupid text editor. I know there are tons of open source RSS Readers with highly sophisticated options and features but I am not all in to that. I want to develop something simple and easy to use.
The main reason why I am posting is because I have a problem with parsing and formating the RSS document. I am able to get the RSS document from the websites such as PFO's but I want to parse it and format it to an easy on the eyes display. I have no experience in XML and for this project I think it will enhance my skills in Java by doing something I know while learning something new. Any help or suggestions guys?? Side Note: I came around this website, http://xerces.apache.org. I know it's a open source XML Parser for Java but I know no clue how to use it.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 3
![]() |
I found this online book on the internet: http://www.cafeconleche.org/books/xmljava/
May be useful, especially chapter 5 . |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
You can also check the out this class in the Java 1.5 api.
|
|
|
|
|
|
#4 |
|
King of Portal
|
Don't know if this helps exactly but I used an XML document for a program of mine to hold the configuration info and I created a class to parse that info. I couldn't quite understand how to implement the java xml classes hehe. Here's the code anyways, but be warned it only works with simple tags such as <this> </this> it doesn't support attributes that are embedded in the tags.
import java.io.File;
import java.io.RandomAccessFile;
public class ConfigParser
{
/////////////////////
// Instance Fields //
/////////////////////
// The contents of the XML configuration file
private String xmlContents = "";
// Flag to denote successful creation of the parser
public boolean SUCCESS = true;
//****************************************************************************************************//
/////////////////
// Constructor //
/////////////////
// If the object is constructed this way it means the the file that was passed is invalid
public ConfigParser()
{
SUCCESS = false;
}
public ConfigParser(String fileName)
{
try
{
File xmlFile = new File(fileName);
RandomAccessFile temp = new RandomAccessFile(xmlFile, "r");
byte[] charStream = new byte[(int)xmlFile.length()];
temp.read(charStream);
temp.close();
for(int i = 0; i < charStream.length; i++)
{
xmlContents += (char)charStream[i];
}
}
catch(Exception e)
{
System.err.println("ERROR: XML Parsing");
SUCCESS = false;
}
}
//****************************************************************************************************//
/////////////
// Methods //
/////////////
// Returns the value of a given XML tag
public String getValue(String tag)
{
String result;
int offset = tag.length() + 1;
result = xmlContents.substring(xmlContents.toLowerCase().indexOf(tag.toLowerCase()) + offset, xmlContents.toLowerCase().lastIndexOf("</" + tag.toLowerCase()));
return result;
}
}
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis |
|
|
|
|
|
#5 |
|
Sexy Programmer
|
Thanks for the help grimpirate but do you know that there is a similar class in the Java API for configuration and "Preferences". It's the java.util.prefs.* package. Check it out, it's really good and saves the preferences in a XML file just as you do also.
Thanks guys for the links. I am looking in to these now.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#6 | |
|
Programmer
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0
![]() |
Quote:
P.S. that online book posted earlier looks like it has pretty good info. P.P.S. My news reader has editable and drag-droppable file folders on he left. Something else to think about as it was a hurdle to develop.
__________________
Java Blog |
|
|
|
|
|
|
#7 |
|
Sexy Programmer
|
Help me A LOT! Thanks alcdotcom!!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#8 |
|
Programmer
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0
![]() |
Here's another article you might find useful. This one addresses a way to stop the SAX parser in mid parse. Tere is no built-in way to stop a SAX parser, so the gist is that you have to throw a SAXException to stop it. Why would you want to do this? Well, imagine this scenario. You load a feed, not knowing what type it is (RSS, ATOM, etc). You have parser who's sole purpose is to detemine what type of feed it is and then hand it off to an instance of the appropriate parser type. You could allow it to parse the entire document, reading only the first element to get the type, or you could abort the parsing after the type is obtained. Obviously, aborting the parse could save you loads of time, especially if you've got lots of documents to parse or a long document. Otherwise you're parsing it twice. What I did was create a sub-class of SAXParserException called ParsingAbortException (doesn't matter what you call it). This way, you can easily differentiate between your exception and actual SAXParserExceptions.
__________________
Java Blog |
|
|
|
|
|
#9 |
|
Sexy Programmer
|
Your posts gave me a lot of direction, thanks man!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#10 |
|
Programmer
Join Date: Jan 2006
Location: Dallas, TX
Posts: 49
Rep Power: 0
![]() |
No problem. I've been there and I thought I'd try to save you a little time. I haven't looked at the new XML handling of 1.6 (Mustang), but I've heard that it's improved.
__________________
Java Blog |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| okay patience please... a good starting point?? | Que | Python | 10 | Apr 20th, 2006 2:11 PM |
| Starting Language, whisch is best. | Davelee01 | Coder's Corner Lounge | 9 | Nov 8th, 2005 10:14 AM |
| Hex editing - How to get starting modding exe files?? | wazoo | Assembly | 9 | Sep 20th, 2005 11:51 AM |
| C++ Starting Off Again | brokenhope | C++ | 11 | Apr 15th, 2005 4:59 PM |
| Just starting Java. Where to go? [Solved] | natefico | Java | 12 | Feb 2nd, 2005 7:24 PM |