Package org.eclipse.rdf4j.rio.rdfxml
Class RDFXMLParser
- java.lang.Object
-
- org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
-
- org.eclipse.rdf4j.rio.helpers.XMLReaderBasedParser
-
- org.eclipse.rdf4j.rio.rdfxml.RDFXMLParser
-
- All Implemented Interfaces:
RDFParser,ErrorHandler
public class RDFXMLParser extends XMLReaderBasedParser implements ErrorHandler
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 theorg.xml.sax.driverproperty. This parser is not thread-safe, therefore it's public methods are synchronized.To parse a document using this parser:
- Create an instance of RDFXMLParser, optionally supplying it with your own ValueFactory.
- Set the RDFHandler.
- Optionally, set the ParseErrorListener and/or ParseLocationListener.
- Optionally, specify whether the parser should verify the data it parses and whether it should stop immediately when it finds an error in the data (both default to true).
- Call the parse method.
// 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");Note that JAXP entity expansion limits may apply. Check the documentation on limits and using the jaxp.properties file if you get one of the following errors:
JAXP00010001: The parser has encountered more than "64000" entity expansions in this document JAXP00010004: The accumulated size of entities is ... that exceeded the "50,000,000" limit
As a work-around, try passing
-Djdk.xml.totalEntitySizeLimit=0 -DentityExpansionLimit=0to the JVM.- Author:
- Arjohn Kampman
- See Also:
ValueFactory,RDFHandler,ParseErrorListener,ParseLocationListener
-
-
Field Summary
-
Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
rdfHandler, valueFactory
-
-
Constructor Summary
Constructors Constructor Description RDFXMLParser()Creates a new RDFXMLParser that will use aSimpleValueFactoryto create RDF model objects.RDFXMLParser(org.eclipse.rdf4j.model.ValueFactory valueFactory)Creates a new RDFXMLParser that will use the supplied ValueFactory to create RDF model objects.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.eclipse.rdf4j.model.LiteralcreateLiteral(String label, String lang, org.eclipse.rdf4j.model.IRI datatype)protected org.eclipse.rdf4j.model.ResourcecreateNode(String nodeID)voiderror(SAXParseException exception)Implementation of SAX ErrorHandler.errorvoidfatalError(SAXParseException exception)Implementation of SAX ErrorHandler.fatalErrorbooleangetParseStandAloneDocuments()Returns whether the parser is currently in a mode to parse stand-alone RDF documents.RDFFormatgetRDFFormat()SAXResultgetSAXResult(String baseURI)Collection<RioSetting<?>>getSupportedSettings()voidparse(InputStream in, String baseURI)voidparse(Reader reader, String baseURI)protected voidreportError(Exception e, RioSetting<Boolean> setting)OverridesAbstractRDFParser.reportError(String, RioSetting), adding line- and column number information to the error.protected voidreportError(String msg, RioSetting<Boolean> setting)OverridesAbstractRDFParser.reportError(String, RioSetting), adding line- and column number information to the error.protected voidreportFatalError(Exception e)OverridesAbstractRDFParser.reportFatalError(Exception), adding line- and column number information to the error.protected voidreportFatalError(String msg)OverridesAbstractRDFParser.reportFatalError(String), adding line- and column number information to the error.protected voidreportWarning(String msg)OverridesAbstractRDFParser.reportWarning(String), adding line- and column number information to the error.protected voidsetBaseURI(String baseURI)protected voidsetBaseURI(org.eclipse.rdf4j.common.net.ParsedIRI baseURI)voidsetParseStandAloneDocuments(boolean standAloneDocs)Sets the parser in a mode to parse stand-alone RDF documents.voidwarning(SAXParseException exception)Implementation of SAX ErrorHandler.warning-
Methods inherited from class org.eclipse.rdf4j.rio.helpers.XMLReaderBasedParser
getCompulsoryXmlFeatureSettings, getCompulsoryXmlPropertySettings, getOptionalXmlFeatureSettings, getOptionalXmlPropertySettings, getXMLReader
-
Methods inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser
clear, clearBNodeIDMap, createBNode, createBNode, createLiteral, createNode, createStatement, createStatement, createURI, getNamespace, getParseErrorListener, getParseLocationListener, getParserConfig, getRDFHandler, initializeNamespaceTableFromConfiguration, preserveBNodeIDs, reportError, reportError, reportError, reportFatalError, reportFatalError, reportFatalError, reportLocation, reportWarning, resolveURI, set, setNamespace, setParseErrorListener, setParseLocationListener, setParserConfig, setPreserveBNodeIDs, setRDFHandler, setValueFactory
-
-
-
-
Constructor Detail
-
RDFXMLParser
public RDFXMLParser()
Creates a new RDFXMLParser that will use aSimpleValueFactoryto create RDF model objects.
-
RDFXMLParser
public RDFXMLParser(org.eclipse.rdf4j.model.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()
- Specified by:
getRDFFormatin interfaceRDFParser
-
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
- Specified by:
parsein interfaceRDFParser- Throws:
IOExceptionRDFParseExceptionRDFHandlerException
-
parse
public void parse(Reader reader, String baseURI) throws IOException, RDFParseException, RDFHandlerException
- Specified by:
parsein interfaceRDFParser- Throws:
IOExceptionRDFParseExceptionRDFHandlerException
-
getSupportedSettings
public Collection<RioSetting<?>> getSupportedSettings()
- Specified by:
getSupportedSettingsin interfaceRDFParser- Overrides:
getSupportedSettingsin classAbstractRDFParser
-
setBaseURI
protected void setBaseURI(org.eclipse.rdf4j.common.net.ParsedIRI baseURI)
- Overrides:
setBaseURIin classAbstractRDFParser
-
setBaseURI
protected void setBaseURI(String baseURI)
- Overrides:
setBaseURIin classAbstractRDFParser
-
createNode
protected org.eclipse.rdf4j.model.Resource createNode(String nodeID) throws RDFParseException
- Overrides:
createNodein classAbstractRDFParser- Throws:
RDFParseException
-
createLiteral
protected org.eclipse.rdf4j.model.Literal createLiteral(String label, String lang, org.eclipse.rdf4j.model.IRI datatype) throws RDFParseException
- Overrides:
createLiteralin classAbstractRDFParser- Throws:
RDFParseException
-
reportWarning
protected void reportWarning(String msg)
OverridesAbstractRDFParser.reportWarning(String), adding line- and column number information to the error.- Overrides:
reportWarningin classAbstractRDFParser
-
reportError
protected void reportError(String msg, RioSetting<Boolean> setting) throws RDFParseException
OverridesAbstractRDFParser.reportError(String, RioSetting), adding line- and column number information to the error.- Overrides:
reportErrorin classAbstractRDFParser- Throws:
RDFParseException
-
reportError
protected void reportError(Exception e, RioSetting<Boolean> setting) throws RDFParseException
OverridesAbstractRDFParser.reportError(String, RioSetting), adding line- and column number information to the error.- Overrides:
reportErrorin classAbstractRDFParser- Throws:
RDFParseException
-
reportFatalError
protected void reportFatalError(String msg) throws RDFParseException
OverridesAbstractRDFParser.reportFatalError(String), adding line- and column number information to the error.- Overrides:
reportFatalErrorin classAbstractRDFParser- Throws:
RDFParseException
-
reportFatalError
protected void reportFatalError(Exception e) throws RDFParseException
OverridesAbstractRDFParser.reportFatalError(Exception), adding line- and column number information to the error.- Overrides:
reportFatalErrorin classAbstractRDFParser- Throws:
RDFParseException
-
warning
public void warning(SAXParseException exception) throws SAXException
Implementation of SAX ErrorHandler.warning- Specified by:
warningin interfaceErrorHandler- Throws:
SAXException
-
error
public void error(SAXParseException exception) throws SAXException
Implementation of SAX ErrorHandler.error- Specified by:
errorin interfaceErrorHandler- Throws:
SAXException
-
fatalError
public void fatalError(SAXParseException exception) throws SAXException
Implementation of SAX ErrorHandler.fatalError- Specified by:
fatalErrorin interfaceErrorHandler- Throws:
SAXException
-
-