Results 1 to 3 of 3
  1. #1
    cavsfan223 is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Stuck on this problem, need help!

    Hey guys I'm having a lot of trouble with this project

    The Problem

    RSS (Really Simple Syndication) is an XML application for distributing web content that changes frequently. Many news-related sites, weblogs and other online publishers syndicate their content as an RSS Feed to whoever wants it.

    For this project your task is to write a program that asks the user for the URL of an RSS 2.0 feed and for the name of an output file, reads the RSS feed into an XMLTree object and then uses the information in the XMLTree object to generate in the output file a nicely formatted HTML page with table of links to all the news items in the original feed.

    Input: RSS 2.0 XML Document

    Here is a simplified description of the structure of an RSS 2.0 XML document. RSS 2.0 documents can contain a few other tags and features, but these are the ones you will need for the project.

    <rss version="2.0">
    <channel>
    <title>Title goes here</title>
    <link>Link goes here</link>
    <description>Description goes here</description>
    <item>
    <title>Optional title goes here</title>
    <description>Optional description goes here</description>
    <link>Optional link goes here</link>
    <pubDate>Optional publication date goes here</pubDate>
    <source url="the source URL">Optional source goes here</source>
    ...
    </item>
    ...
    </channel>
    </rss>

    Note the following properties of RSS 2.0 XML documents:

    The children of the <channel> tag and of the <item> tag can occur in any order; do not assume they will appear in the order above. Furthermore there can be other children of other types not listed above.
    <title>, <link>, and <description> are required children of the <channel> tag, i.e., you should assume they are present.
    All the children of <item> tag are optional, i.e., do not assume they are present; however, either <title> or <description> must be present.
    If a <source> tag appears as a child of an <item> tag, it must have a url attribute.
    Note that when your program creates an XMLTree object from a given RSS 2.0 feed, if it is successful, all you know is that the input is a valid XML document. It is up to your program to check that the label of the root of the XMLTree is an <rss> tag and that it has a version attribute with value "2.0". After that, your program can assume that the input is indeed a valid RSS 2.0 feed and the XMLTree has the structure described above; in other words, you do not need to check for the existence of the <channel> tag, or the <title>, <link>, and <description> tags inside that. However, make sure you do not make any assumptions that are not specified in the structure described above.

    Output: HTML Web Page

    These are the minimum requirements for the generated web page. If you think you can produce better output or include more information, you should consult your instructor to make sure that any changes you want to implement are acceptable. This is what your output should include:

    the <channel> title as the page title
    a header with the page title inside a link to the <channel> link
    a paragraph with the <channel> description
    a table with appropriate headers; each row should correspond to one news item with the following columns:
    the publication date, if present, or "No date available"
    the source, if present, which should be linked to the source url, or "No source available"
    the title, if present, otherwise the description, which should be linked if a link for the news item is available
    You can see an example of the output here (note that the links may be outdated and no longer available).

    So far I have...

    import components.simplereader.SimpleReader;
    import components.simplereader.SimpleReader1L;
    import components.simplewriter.SimpleWriter;
    import components.simplewriter.SimpleWriter1L;
    import components.xmltree.XMLTree;
    import components.xmltree.XMLTree1;

    /**
    * Program to convert an XML RSS (version 2.0) feed from a given URL into the
    * corresponding HTML output file.
    *
    * @author Put your name here
    *
    */
    public final class RSSReader {

    /**
    * Private constructor so this utility class cannot be instantiated.
    */
    private RSSReader() {
    }

    /**
    * Outputs the opening tags in the generated HTML file.
    *
    * @param channel
    * the channel element XMLTree
    * @param out
    * the output stream
    * @updates {@code out.content}
    * @requires <pre>
    * {@code [the root of channel is a <channel> tag] and out.is_open}
    * </pre>
    * @ensures <pre>
    * {@code out.content = #out.content * [the HTML opening tags]}
    * </pre>
    */
    private static void outputHeader(XMLTree channel, SimpleWriter out) {
    assert channel != null : "Violation of: channel is not null";
    assert out != null : "Violation of: out is not null";
    assert channel.isTag() && channel.label().equals("channel") : ""
    + "Violation of: the label root of channel is a <channel> tag";
    assert out.isOpen() : "Violation of: out.is_open";

    /*
    * TODO: fill in body
    */
    }

    /**
    * Outputs the closing tags in the generated HTML file.
    *
    * @param out
    * the output stream
    * @updates {@code out.contents}
    * @requires <pre>
    * {@code out.is_open}
    * </pre>
    * @ensures <pre>
    * {@code out.content = #out.content * [the HTML closing tags]}
    * </pre>
    */
    private static void outputFooter(SimpleWriter out) {
    assert out != null : "Violation of: out is not null";
    assert out.isOpen() : "Violation of: out.is_open";

    /*
    * TODO: fill in body
    */
    }

    /**
    * Finds the first occurrence of the given tag among the children of the given
    * {@code XMLTree} and return its index; returns -1 if not found.
    *
    * @param xml
    * the {@code XMLTree} to search
    * @param tag
    * the tag to look for
    * @return the index of the first child of type tag of the {@code XMLTree} or -1
    * if not found
    * @requires <pre>
    * {@code [the label of the root of xml is a tag]}
    * </pre>
    * @ensures <pre>
    * {@code getChildElement =
    * [the index of the first child of type tag of the {@code XMLTree} or
    * -1 if not found]}
    * </pre>
    */
    private static int getChildElement(XMLTree xml, String tag) {
    int p = xml.numberOfChildren();
    return p;

    /*
    * TODO: fill in body
    */
    }

    /**
    * Processes one news item and outputs one table row. The row contains three
    * elements: the publication date, the source, and the title (or description) of
    * the item.
    *
    * @param item
    * the news item
    * @param out
    * the output stream
    * @updates {@code out.content}
    * @requires <pre>
    * {@code [the label of the root of item is an <item> tag] and out.is_open}
    * </pre>
    * @ensures <pre>
    * {@code out.content = #out.content *
    * [an HTML table row with publication date, source, and title of news item]}
    * </pre>
    */
    private static void processItem(XMLTree item, SimpleWriter out) {
    assert item != null : "Violation of: item is not null";
    assert out != null : "Violation of: out is not null";
    assert item.isTag() && item.label().equals("item") : ""
    + "Violation of: the label root of item is an <item> tag";
    assert out.isOpen() : "Violation of: out.is_open";

    /*
    * TODO: fill in body
    */
    }

    /**
    * Main method.
    *
    * @param args
    * the command line arguments; unused here
    */
    public static void main(String[] args) {
    SimpleReader in = new SimpleReader1L();
    SimpleWriter out = new SimpleWriter1L();
    out.println("Enter the URL of an RSS 2.0 feed: ");
    XMLTree item = new XMLTree1(
    "http://xml.weather.yahoo.com/forecastrss/43210.xml");
    item.toString();
    item.display();
    String s = item.label();
    if (s == "rss") {
    String t = item.attributeValue("version");
    if (t == "2.0") {
    getChildElement(item, s);
    }
    }

    /*
    * TODO: fill in body
    */

    in.close();
    out.close();
    }

    }

  2. #2
    cavsfan223 is offline Member
    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Default Re: Stuck on this problem, need help!

    Also how do I copy paste it directly from eclipse so it's more readable?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Stuck on this problem, need help!

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Stuck on homework problem (1st year Java programmer)
    By s1l3nced in forum New To Java
    Replies: 10
    Last Post: 02-28-2012, 12:27 AM
  2. Stuck, need help please
    By Johnny2009 in forum New To Java
    Replies: 3
    Last Post: 11-03-2011, 10:25 PM
  3. Kind of stuck on starting a problem..
    By kmjt in forum New To Java
    Replies: 11
    Last Post: 01-31-2011, 07:34 AM
  4. Help please, stuck on for statement problem.
    By shroomiin in forum New To Java
    Replies: 3
    Last Post: 10-30-2009, 01:27 PM
  5. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 02:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •