S
sal
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
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