Annotation of java/classes/org/w3c/rdf/examples/ParseAndSerialize.java, revision 1.1
1.1 ! barstow 1: /**
! 2: * Copyright © Sergey Melnik (Stanford University, Database Group)
! 3: *
! 4: * Distribution policies are governed by the W3C software license.
! 5: * http://www.w3.org/Consortium/Legal/copyright-software
! 6: *
! 7: * All Rights Reserved.
! 8: *
! 9: * @author Sergey Melnik <melnik@db.stanford.edu>
! 10: */
! 11:
! 12: package org.w3c.rdf.examples;
! 13:
! 14: import org.xml.sax.SAXException;
! 15: import org.w3c.rdf.model.*;
! 16: import org.w3c.rdf.util.*;
! 17:
! 18: /**
! 19: * A simple demo program that parses RDF at a given URL,
! 20: * serializes it back into RDF/XML, and dumps the triples.
! 21: *
! 22: * <p>Try <code>java org.w3c.rdf.examples.ParseAndSerialize http://www-db.stanford.edu/~melnik/</code>
! 23: */
! 24:
! 25: public class ParseAndSerialize {
! 26:
! 27: public static void main(String[] args) throws Exception {
! 28:
! 29: if(args.length == 0) {
! 30: System.err.println("ParseAndSerialize <fileNameOrURL>");
! 31: System.exit(1);
! 32: }
! 33:
! 34: String fileNameOrURL = args[0];
! 35: RDFFactory f = new RDFFactoryImpl();
! 36: Model m = f.createModel();
! 37:
! 38: try {
! 39: RDFUtil.parse(fileNameOrURL, f.createParser(), m);
! 40: } catch (SAXException se) {
! 41: System.err.println("Exception during parsing:");
! 42: throw se.getException();
! 43: }
! 44:
! 45: System.err.println("\nTRIPLES:\n");
! 46: RDFUtil.printStatements(m, System.out);
! 47:
! 48: System.err.println("\nSERIALIZED MODEL:\n");
! 49: RDFUtil.dumpModel(m, System.out, f.createSerializer());
! 50:
! 51: System.err.println("\nModel " + m.getURI() + " of size " + m.size() + "\n");
! 52: }
! 53: }
Webmaster