You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jena.apache.org by "namedgraph (via GitHub)" <gi...@apache.org> on 2026/10/18 14:36:18 UTC
[I] RRX SAX: inside rdf:parseType="Literal" ends the document ("Inconsistent parserMode:TOP") [jena]
namedgraph opened a new issue, #4334:
URL: https://github.com/apache/jena/issues/4334
### Version
6.1.0 (same code on `main`)
### What happened?
An XML literal whose content contains an `rdf:RDF` element fails to parse with the default RDF/XML parser (`RDFXML-SAX`):
```xml
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://example.org/">
<rdf:Description rdf:about="http://example.org/s">
<ex:p rdf:parseType="Literal"><x xmlns="http://example.org/x"><rdf:RDF><rdf:Description rdf:about="http://example.org/inner"/></rdf:RDF></x></ex:p>
<ex:q>after</ex:q>
</rdf:Description>
</rdf:RDF>
```
```
$ riot --validate --syntax=RDFXML min.rdf
ERROR riot :: [line: 5, col: 21] Inconsistent parserMode:TOP
```
The document is valid RDF/XML. The content of a `parseTypeLiteralPropertyElt` is the `literal` symbol, "Any XML element content that is allowed according to [XML10] ... Rule [43] content" (RDF/XML §7.2.33), and "All information items contained inside XML elements matching the parseTypeLiteralPropertyElt production form XML literals and do not follow this mapping" (§6).
The other parsers agree with the spec. Parsing the same input:
| parser | result |
|---|---|
| `RRX.RDFXML_StAX_ev` | ok, isomorphic |
| `RRX.RDFXML_StAX_sr` | ok, isomorphic |
| `RRX.RDFXML_ARP1` | ok, isomorphic |
| `RRX.RDFXML_SAX` (default `Lang.RDFXML`) | `Inconsistent parserMode:TOP` |
Jena's own writer produces this form: an `rdf:XMLLiteral` whose lexical form contains `<rdf:RDF>` is written by `RDFFormat.RDFXML_PLAIN` as `rdf:parseType="Literal"` markup, so the default write cannot be read back by the default parser. Any `rdf:RDF` triggers it, even an empty `<rdf:RDF/>`; other `rdf:` elements in the literal (`rdf:Description`, `rdf:Seq`) parse fine.
Cause: in `ParserRRX_SAX.endElement`, the `rdf:RDF` check comes before the XML literal check:
```java
public void endElement(String namespaceURI, String localName, String qName) {
if ( qNameMatches(rdfNS, rdfRDF, namespaceURI, localName) ) {
decIndent();
parserMode(ParserMode.TOP);
return;
}
...
if ( xmlLiteralCollecting() ) {
```
`startElement` checks `xmlLiteralCollecting()` first, so the literal's `<rdf:RDF>` is collected, but its `</rdf:RDF>` is not: it returns early, leaving the parser in `TOP` and the element depth one short, and a later end tag (`</rdf:Description>`, line 5) reaches the `default` branch of the mode switch. Testing `xmlLiteralCollecting()` before the `rdf:RDF` check, as `startElement` does, should fix it.
We hit it in LinkedDataHub, where a stored XML literal holds a SPARQL CONSTRUCT result as RDF/XML; every Jena client reading the containing document as RDF/XML failed.
### Relevant output and stacktrace
```
ERROR riot :: [line: 5, col: 21] Inconsistent parserMode:TOP
```
### Are you interested in making a pull request?
Yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org
Re: [I] RRX SAX: inside rdf:parseType="Literal" ends the document ("Inconsistent parserMode:TOP") [jena]
Posted by "namedgraph (via GitHub)" <gi...@apache.org>.
namedgraph commented on issue #4334:
URL: https://github.com/apache/jena/issues/4334#issuecomment-6251330776
It can also lose data silently. With two nested `rdf:RDF` elements in the literal, `RDFXML-SAX` reports no error and returns an empty graph:
```xml
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ex="http://example.org/">
<rdf:Description rdf:about="http://example.org/s">
<ex:p rdf:parseType="Literal"><rdf:RDF><rdf:RDF/></rdf:RDF></ex:p>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/t">
<ex:q>lost</ex:q>
</rdf:Description>
</rdf:RDF>
```
```
$ riot --syntax=RDFXML --output=nt silent.rdf
$ echo $?
0
```
| parser | triples |
|---|---|
| `RRX.RDFXML_SAX` | 0, no error |
| `RRX.RDFXML_StAX_sr` | 2 |
| `RRX.RDFXML_StAX_ev` | 2 |
| `RRX.RDFXML_ARP1` | 2 |
The same cause: each `</rdf:RDF>` inside the literal resets the parser to `TOP` and is not collected. With two of them, the parser is back at the top level when the document's own `</rdf:Description>` and `</rdf:RDF>` arrive, so it finishes without an error and without the triples.
We hit this on a real document of 20 triples, where `RDFXML-SAX` read 1: an XML literal holding a SPARQL CONSTRUCT result that itself included a resource with such a literal.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org
Re: [I] RRX SAX: inside rdf:parseType="Literal" ends the document ("Inconsistent parserMode:TOP") [jena]
Posted by "afs (via GitHub)" <gi...@apache.org>.
afs closed issue #4334: RRX SAX: </rdf:RDF> inside rdf:parseType="Literal" ends the document ("Inconsistent parserMode:TOP")
URL: https://github.com/apache/jena/issues/4334
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@jena.apache.org
For additional commands, e-mail: issues-help@jena.apache.org