Skip to content

XML 1.1 version not supported error in Java #6

Description

@ntung

I ran into the following error:

c.h.h.j.r.m.impl.RDFDefaultErrorHandler (line 1 column 20): XML version "1.1" is not supported, only XML 1.0 is supported.

This error is coming from Apache Jena's RDF parser when it encounters an XML document that declares version 1.1. The error message tells you exactly where the issue is:

What's happening:

We're trying to parse an RDF/XML file
That file has <?xml version="1.1"?> in its declaration (at line 1, column 20)
Jena's XML parser only supports XML 1.0

Solutions:

Option 1: Preprocess the file

javaString content = Files.readString(Path.of("file.rdf"));
content = content.replaceFirst("<?xml version=\"1.1\"", "<?xml version=\"1.0\"");
Model model = ModelFactory.createDefaultModel();
model.read(new StringReader(content), null);

Option 2: Use a different parser
Try switching to Turtle or N-Triples format if you control the source data, as they don't have this XML version dependency.

Option 3: Convert upstream
If we're fetching this from an external source, we might need to preprocess it before passing to Jena, or contact the data provider to use XML 1.0.
The error is specifically in c.h.h.j.r.m.impl.RDFDefaultErrorHandler which is Jena's error reporting mechanism - the actual parsing failure happens in the XML parser underneath.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions