rdfowljenairi

Bad character in IRI in Jena when reading OWL/RDF model


I have a org.apache.jena.riot.RiotException: Bad character in IRI (space) exception when reading an OWL/RDL model in Jena.

I know that it's because I have a space in an IRI declaration in an XML namespace declaration (which is not allowed), but as I am using Jena in an open Source tool I developed to create the graph corresponding to an ontology, I would like to know the number of the line in the (XML) model where the error occur. Is it possible in Jena when catching this exception?


Solution

  • You can supply an error handler using

    RDFParser.source("filename").errorHandler(...).toModel();
    

    It will actually be warning from the parser (the error is generated later when the line number isn't available)

    To change it to an error:

      Map<String, Object> properties = new HashMap<>();
      properties.put("WARN_BAD_NAMESPACE_URI", "EM_ERROR");
      Context cxt = new Context().set(SysRIOT.sysRdfReaderProperties, properties);
      RDFParser.source(filename)
               .context(cxt)
               .errorHandler(....)
               .toModel();