Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] Displaying a JDOM objects data content - help needed

sal achhala

2005-03-10

Replies:

I have a problem with using JDOM to output contents of an xml file.

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 = new SyndFeedOutput();

// 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

_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.