|
|
|
I will explain the use of the RDFParser by a example:
import org.juniverse.rdf.RDFDocument;
import org.juniverse.rdf.RDFItem;
import org.juniverse.rdf.RDFDomParser;
import org.juniverse.rdf.RDFParser;
public class RDFTest {
public static void main(String[] args) {
// check for uri-arg:
if (args.lenght < 1) {
System.out.println("Please specify the uri arg!");
return;
}
// create a new RDFParser:
RDFParser parser = new RDFDomParser();
// set the URI of the RDF resource,
// for example http://www.heise.de/newsticker/heise.rdf
parser.setUri(args[0]);
// start parsing the RDF file
parser.parse();
// get the RDFDocument from the parser:
RDFDocument doc = parser.getRdfDoc();
// print the title and the description of the RDF channel
// to the console:
System.out.println("Channel: " + doc.getChannelTitle());
System.out.println(doc.getChannelDescription());
// run over all RDFItem's that are included in the channel:
while(doc.hasMoreItems()) {
// get the next Item from the RDFDocument:
RDFItem item = doc.getNextItem();
// print the title of the RDFItem:
System.out.println("Title: " + item.getTitle());
}
}
}
|
|
|