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

  - 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.
  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");

  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=0` to the JVM.
  Author:
    Arjohn Kampman
  See Also:
    `ValueFactory`, `RDFHandler`, `ParseErrorListener`, `ParseLocationListener`

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.eclipse.rdf4j.rio.RDFParser

      `RDFParser.DatatypeHandling`

  - ### Field Summary

    - ### Fields inherited from class org.eclipse.rdf4j.rio.helpers.AbstractRDFParser

      `rdfHandler, valueFactory`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `RDFXMLParser()` Creates a new RDFXMLParser that will use a `SimpleValueFactory` 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

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected Literal` | `createLiteral(String label, String lang, IRI datatype)` Creates a `Literal` object with the supplied parameters.
    `protected Resource` | `createNode(String nodeID)` Creates a `BNode` or Skolem `IRI` object for the specified identifier.
    `void` | `error(SAXParseException exception)` Implementation of SAX ErrorHandler.error
    `void` | `fatalError(SAXParseException exception)` Implementation of SAX ErrorHandler.fatalError
    `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.
    `SAXResult` | `getSAXResult(String baseURI)`
    `Collection<RioSetting<?>>` | `getSupportedSettings()`
    `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(Exception e, RioSetting<Boolean> setting)` Overrides `AbstractRDFParser.reportError(String, RioSetting)`, adding line- and column number information to the error.
    `protected void` | `reportError(String msg, RioSetting<Boolean> setting)` Overrides `AbstractRDFParser.reportError(String, RioSetting)`, adding line- and column number information to the error.
    `protected void` | `reportFatalError(Exception e)` Overrides `AbstractRDFParser.reportFatalError(Exception)`, adding line- and column number information to the error.
    `protected void` | `reportFatalError(String msg)` Overrides `AbstractRDFParser.reportFatalError(String)`, adding line- and column number information to the error.
    `protected void` | `reportWarning(String msg)` Overrides `AbstractRDFParser.reportWarning(String)`, adding line- and column number information to the error.
    `protected void` | `setBaseURI(ParsedIRI baseURI)` Sets the base URI for resolving relative URIs.
    `protected void` | `setBaseURI(String baseURI)` Parses the supplied URI-string and sets it as the base URI for resolving relative URIs.
    `void` | `setParseStandAloneDocuments(boolean standAloneDocs)` Sets the parser in a mode to parse stand-alone RDF documents.
    `void` | `warning(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, datatypeHandling, getNamespace, getParseErrorListener, getParseLocationListener, getParserConfig, getRDFHandler, initializeNamespaceTableFromConfiguration, preserveBNodeIDs, reportError, reportError, reportError, reportFatalError, reportFatalError, reportFatalError, reportLocation, reportWarning, resolveURI, set, 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`

    - ### Methods inherited from interface org.eclipse.rdf4j.rio.RDFParser

      `parse, parse`

- - ### Constructor Detail

    - #### RDFXMLParser

          public RDFXMLParser()

      Creates a new RDFXMLParser that will use a `SimpleValueFactory` 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.
      Specified by:
        `getRDFFormat` in interface `RDFParser`

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

      Description copied from interface: `RDFParser`
      Parses the data from the supplied InputStream, using the supplied baseURI to resolve any relative URI references.
      Specified by:
        `parse` in interface `RDFParser`
      Parameters:
        `in` - The InputStream from which to read the data.
        `baseURI` - The URI associated with the data in the InputStream. May be `null`. Parsers for syntax formats that do not support relative URIs will ignore this argument.

        Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).

      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.

    - #### parse

          public void parse(Reader reader,
                            String baseURI)
                     throws IOException,
                            RDFParseException,
                            RDFHandlerException

      Description copied from interface: `RDFParser`
      Parses the data from the supplied Reader, using the supplied baseURI to resolve any relative URI references.
      Specified by:
        `parse` in interface `RDFParser`
      Parameters:
        `reader` - The Reader from which to read the data.
        `baseURI` - The URI associated with the data in the InputStream. May be `null`. Parsers for syntax formats that do not support relative URIs will ignore this argument.

        Note that if the data contains an embedded base URI, that embedded base URI will overrule the value supplied here (see RFC 3986 section 5.1 for details).

      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.

    - #### getSupportedSettings

          public Collection<RioSetting<?>> getSupportedSettings()

      Specified by:
        `getSupportedSettings` in interface `RDFParser`
      Overrides:
        `getSupportedSettings` in class `AbstractRDFParser`
      Returns:
        A collection of `RioSetting`s that are supported by this RDFParser.

    - #### getSAXResult

          public SAXResult getSAXResult(String baseURI)

    - #### setBaseURI

          protected void setBaseURI(ParsedIRI baseURI)

      Description copied from class: `AbstractRDFParser`
      Sets the base URI for resolving relative URIs.
      Overrides:
        `setBaseURI` in class `AbstractRDFParser`

    - #### setBaseURI

          protected void setBaseURI(String baseURI)

      Description copied from class: `AbstractRDFParser`
      Parses the supplied URI-string and sets it as the base URI for resolving relative URIs.
      Overrides:
        `setBaseURI` in class `AbstractRDFParser`

    - #### createNode

          protected Resource createNode(String nodeID)
                                 throws RDFParseException

      Description copied from class: `AbstractRDFParser`
      Creates a `BNode` or Skolem `IRI` object for the specified identifier.
      Overrides:
        `createNode` in class `AbstractRDFParser`
      Parameters:
        `nodeID` - node identifier
      Returns:
        blank node or skolem IRI
      Throws:
        `RDFParseException`

    - #### createLiteral

          protected Literal createLiteral(String label,
                                          String lang,
                                          IRI datatype)
                                   throws RDFParseException

      Description copied from class: `AbstractRDFParser`
      Creates a `Literal` object with the supplied parameters.
      Overrides:
        `createLiteral` in class `AbstractRDFParser`
      Throws:
        `RDFParseException`

    - #### reportWarning

          protected void reportWarning(String msg)

      Overrides `AbstractRDFParser.reportWarning(String)`, adding line- and column number information to the error.
      Overrides:
        `reportWarning` in class `AbstractRDFParser`

    - #### reportError

          protected void reportError(String msg,
                                     RioSetting<Boolean> setting)
                              throws RDFParseException

      Overrides `AbstractRDFParser.reportError(String, RioSetting)`, adding line- and column number information to the error.
      Overrides:
        `reportError` in class `AbstractRDFParser`
      Parameters:
        `msg` - The message to use for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(String, long, long)` .
        `setting` - The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and if `ParserConfig.isNonFatalError(RioSetting)` returns true an exception will be thrown.
      Throws:
        `RDFParseException` - If `RioConfig.get(RioSetting)` returns true, and `ParserConfig.isNonFatalError(RioSetting)` returns true for the given setting.

    - #### reportError

          protected void reportError(Exception e,
                                     RioSetting<Boolean> setting)
                              throws RDFParseException

      Overrides `AbstractRDFParser.reportError(String, RioSetting)`, adding line- and column number information to the error.
      Overrides:
        `reportError` in class `AbstractRDFParser`
      Parameters:
        `e` - The exception whose message will be used for `ParseErrorListener.error(String, long, long)` and for `RDFParseException(String, long, long)` .
        `setting` - The boolean setting that will be checked to determine if this is an issue that we need to look at at all. If this setting is true, then the error listener will receive the error, and if `ParserConfig.isNonFatalError(RioSetting)` returns true an exception will be thrown.
      Throws:
        `RDFParseException` - If `RioConfig.get(RioSetting)` returns true, and `ParserConfig.isNonFatalError(RioSetting)` returns true for the given setting.

    - #### reportFatalError

          protected void reportFatalError(String msg)
                                   throws RDFParseException

      Overrides `AbstractRDFParser.reportFatalError(String)`, adding line- and column number information to the error.
      Overrides:
        `reportFatalError` in class `AbstractRDFParser`
      Throws:
        `RDFParseException`

    - #### reportFatalError

          protected void reportFatalError(Exception e)
                                   throws RDFParseException

      Overrides `AbstractRDFParser.reportFatalError(Exception)`, adding line- and column number information to the error.
      Overrides:
        `reportFatalError` in class `AbstractRDFParser`
      Throws:
        `RDFParseException`

    - #### warning

          public void warning(SAXParseException exception)
                       throws SAXException

      Implementation of SAX ErrorHandler.warning
      Specified by:
        `warning` in interface `ErrorHandler`
      Throws:
        `SAXException`

    - #### error

          public void error(SAXParseException exception)
                     throws SAXException

      Implementation of SAX ErrorHandler.error
      Specified by:
        `error` in interface `ErrorHandler`
      Throws:
        `SAXException`

    - #### fatalError

          public void fatalError(SAXParseException exception)
                          throws SAXException

      Implementation of SAX ErrorHandler.fatalError
      Specified by:
        `fatalError` in interface `ErrorHandler`
      Throws:
        `SAXException`

Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.