Hervé Girod
Hervé Girod

Reputation: 547

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?

Upvotes: 0

Views: 292

Answers (1)

AndyS
AndyS

Reputation: 16700

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();

Upvotes: 2

Related Questions