org.openrdf.rio.rdfxml
Class RDFXMLParser

java.lang.Object
  extended by org.openrdf.rio.helpers.RDFParserBase
      extended by org.openrdf.rio.rdfxml.RDFXMLParser
All Implemented Interfaces:
RDFParser

public class RDFXMLParser
extends RDFParserBase

A parser for XML-serialized RDF. This parser operates directly on the SAX events generated by a SAX-enabled XML parser. The XML parser should be compliant with SAX2. You should specify which SAX parser should be used by setting the org.xml.sax.driver property. This parser is not thread-safe, therefore it's public methods are synchronized.

To parse a document using this parser:

Example code:
 // Use the SAX2-compliant Xerces parser:
 System.setProperty("org.xml.sax.driver", "org.apache.xerces.parsers.SAXParser");
 
 RDFParser parser = new RDFXMLParser();
 parser.setRDFHandler(myRDFHandler);
 parser.setParseErrorListener(myParseErrorListener);
 parser.setVerifyData(true);
 parser.stopAtFirstError(false);
 
 // Parse the data from inputStream, resolving any
 // relative URIs against http://foo/bar:
 parser.parse(inputStream, "http://foo/bar");
 

Author:
Arjohn Kampman
See Also:
ValueFactory, RDFHandler, ParseErrorListener, ParseLocationListener

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.openrdf.rio.RDFParser
RDFParser.DatatypeHandling
 
Field Summary
 
Fields inherited from class org.openrdf.rio.helpers.RDFParserBase
rdfHandler
 
Constructor Summary
RDFXMLParser()
          Creates a new RDFXMLParser that will use a ValueFactoryImpl to create RDF model objects.
RDFXMLParser(ValueFactory valueFactory)
          Creates a new RDFXMLParser that will use the supplied ValueFactory to create RDF model objects.
 
Method Summary
protected  BNode createBNode(String nodeID)
          Creates a BNode object for the specified identifier.
 boolean getParseStandAloneDocuments()
          Returns whether the parser is currently in a mode to parse stand-alone RDF documents.
 RDFFormat getRDFFormat()
          Gets the RDF format that this parser can parse.
 void parse(InputStream in, String baseURI)
          Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.
 void parse(Reader reader, String baseURI)
          Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.
protected  void reportError(String msg)
          Overrides RDFParserBase.reportError(String), adding line- and column number information to the error.
protected  void reportFatalError(Exception e)
          Overrides RDFParserBase.reportFatalError(Exception), adding line- and column number information to the error.
protected  void reportFatalError(String msg)
          Overrides RDFParserBase.reportFatalError(String), adding line- and column number information to the error.
protected  void reportWarning(String msg)
          Overrides RDFParserBase.reportWarning(String), adding line- and column number information to the error.
protected  void setBaseURI(ParsedURI baseURI)
          Sets the base URI for resolving relative URIs.
 void setParseStandAloneDocuments(boolean standAloneDocs)
          Sets the parser in a mode to parse stand-alone RDF documents.
 
Methods inherited from class org.openrdf.rio.helpers.RDFParserBase
clear, clearBNodeIDMap, createBNode, createLiteral, createStatement, createStatement, createURI, datatypeHandling, getNamespace, getParseErrorListener, getParseLocationListener, getParserConfig, getRDFHandler, isValidLanguageTag, preserveBNodeIDs, reportError, reportFatalError, reportFatalError, reportLocation, reportWarning, resolveURI, setBaseURI, setDatatypeHandling, setNamespace, setParseErrorListener, setParseLocationListener, setParserConfig, setPreserveBNodeIDs, setRDFHandler, setStopAtFirstError, setValueFactory, setVerifyData, stopAtFirstError, verifyData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RDFXMLParser

public RDFXMLParser()
Creates a new RDFXMLParser that will use a ValueFactoryImpl to create RDF model objects.


RDFXMLParser

public RDFXMLParser(ValueFactory valueFactory)
Creates a new RDFXMLParser that will use the supplied ValueFactory to create RDF model objects.

Parameters:
valueFactory - A ValueFactory.
Method Detail

getRDFFormat

public final RDFFormat getRDFFormat()
Description copied from interface: RDFParser
Gets the RDF format that this parser can parse.


setParseStandAloneDocuments

public void setParseStandAloneDocuments(boolean standAloneDocs)
Sets the parser in a mode to parse stand-alone RDF documents. In stand-alone RDF documents, the enclosing rdf:RDF root element is optional if this root element contains just one element (e.g. rdf:Description.


getParseStandAloneDocuments

public boolean getParseStandAloneDocuments()
Returns whether the parser is currently in a mode to parse stand-alone RDF documents.

See Also:
setParseStandAloneDocuments(boolean)

parse

public void parse(InputStream in,
                  String baseURI)
           throws IOException,
                  RDFParseException,
                  RDFHandlerException
Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.

Parameters:
in - The InputStream from which to read the data, must not be null.
baseURI - The URI associated with the data in the InputStream, must not be null.
Throws:
IOException - If an I/O error occurred while data was read from the InputStream.
RDFParseException - If the parser has found an unrecoverable parse error.
RDFHandlerException - If the configured statement handler encountered an unrecoverable error.
IllegalArgumentException - If the supplied input stream or base URI is null.

parse

public void parse(Reader reader,
                  String baseURI)
           throws IOException,
                  RDFParseException,
                  RDFHandlerException
Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.

Parameters:
reader - The Reader from which to read the data, must not be null.
baseURI - The URI associated with the data in the InputStream, must not be null.
Throws:
IOException - If an I/O error occurred while data was read from the InputStream.
RDFParseException - If the parser has found an unrecoverable parse error.
RDFHandlerException - If the configured statement handler has encountered an unrecoverable error.
IllegalArgumentException - If the supplied reader or base URI is null.

setBaseURI

protected void setBaseURI(ParsedURI baseURI)
Description copied from class: RDFParserBase
Sets the base URI for resolving relative URIs.

Overrides:
setBaseURI in class RDFParserBase

createBNode

protected BNode createBNode(String nodeID)
                     throws RDFParseException
Description copied from class: RDFParserBase
Creates a BNode object for the specified identifier.

Overrides:
createBNode in class RDFParserBase
Throws:
RDFParseException

reportWarning

protected void reportWarning(String msg)
Overrides RDFParserBase.reportWarning(String), adding line- and column number information to the error.

Overrides:
reportWarning in class RDFParserBase

reportError

protected void reportError(String msg)
                    throws RDFParseException
Overrides RDFParserBase.reportError(String), adding line- and column number information to the error.

Overrides:
reportError in class RDFParserBase
Throws:
RDFParseException
See Also:
RDFParserBase.setStopAtFirstError(boolean)

reportFatalError

protected void reportFatalError(String msg)
                         throws RDFParseException
Overrides RDFParserBase.reportFatalError(String), adding line- and column number information to the error.

Overrides:
reportFatalError in class RDFParserBase
Throws:
RDFParseException

reportFatalError

protected void reportFatalError(Exception e)
                         throws RDFParseException
Overrides RDFParserBase.reportFatalError(Exception), adding line- and column number information to the error.

Overrides:
reportFatalError in class RDFParserBase
Throws:
RDFParseException


Copyright © 2001-2012 Aduna. All Rights Reserved.