Displaying a JDOM objects data content (also using ROME API)

Discussion in 'Java' started by sal, Mar 10, 2005.

  1. sal

    sal Guest

    I have a problem with JDOM – I’ve used the rome api to output a rss feed
    as a JDOM object – this works fine. However I want to output just the
    contents of the Jdom obect (minus the xml tags) but im having problems
    with the following code.

    Code below outputs a jdom object, using the rome api, and its copied
    into a jdom document
    Document doc = outputjdom.outputJDom(feed);

    Next im using the doc.toString() method ( part of jdom) to see if the
    document holds the xml file.

    System.out.println(doc.toString());

    However, it doesn’t display the Document contents. where am I going
    wrong ? and what do I need to do to start outputing the contents ? I
    think the problem lies with the way im assigning the ouputted jdom
    object to a jdom document here:

    Document doc = outputjdom.outputJDom(feed);

    any ideas would be appreciated.

    console output when the code is run:

    init:
    deps-jar:
    compile:
    run:
    [Document: No DOCTYPE declaration, Root is [Element: <rss/>]]
    content size is 1
    BUILD SUCCESSFUL (total time: 2 seconds)






    /*
    * Created on Feb 23, 2005
    */

    import com.sun.syndication.feed.synd.SyndFeed;
    import com.sun.syndication.io.SyndFeedInput;
    import com.sun.syndication.io.XmlReader;
    import com.sun.syndication.io.SyndFeedOutput;
    import java.io.File;
    import java.io.StringReader;
    import java.net.URL;

    import org.jdom.output.XMLOutputter;
    import org.jdom.*;
    import org.jdom.Document;
    import org.jdom.input.SAXBuilder;

    import java.io.*;
    import java.util.*;

    /**
    * It Reads and prints any RSS/Atom feed type.
    *
    */
    public class FeedReader {

    public static void main(String[] args) {

    try {
    URL feedUrl = new URL(args[0]);

    //to read in & parse the rss/atom feed frm the //internet
    //based on the ROME API
    SyndFeedInput input = new SyndFeedInput();
    //syndfeed is a bean interface which conatins the entire rss feed for
    //the given URL
    SyndFeed feed = input.build(new XmlReader(feedUrl));




    //prepare output of the retrieved feed as a Jdom object, xml string or
    write to a file
    SyndFeedOutput outputjdom = newSyndFeedOutput();
    // will output feed as jdom
    Document doc = outputjdom.outputJDom(feed);
    //doc.toString() is part of jdom – should output the document to console
    System.out.println(doc.toString());

    Element root = doc.getRootElement();
    System.out.println("content size is "+root.getContentSize());
    }//end try
    catch (Exception ex) {
    ex.printStackTrace();
    System.out.println("ERROR: "+ex.getMessage());
    }//catch

    }//end main

    }//end class
    sal, Mar 10, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Wendy S
    Replies:
    1
    Views:
    6,347
    Darren Davison
    Aug 5, 2003
  2. Bernd Oninger
    Replies:
    4
    Views:
    12,247
    GIMME
    Jun 21, 2004
  3. sal
    Replies:
    0
    Views:
    382
  4. Tinker
    Replies:
    4
    Views:
    5,285
    Harry Bosch
    Oct 9, 2005
  5. Bernd Oninger
    Replies:
    3
    Views:
    2,871
    GIMME
    Jun 21, 2004
Loading...

Share This Page