On 22/09/11 10:09, Laurent Pellegrino wrote:
Hi all,
It seems it is impossible to use the BIO serializer/deserializer with
data which are not retrieved from a dataset.
Hereafter is a simple usecase:
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Binding b = BindingFactory.create();
b.add(Var.alloc("test"), Node.createLiteral("21", XSDDatatype.XSDint));
BindingOutputStream bos = new BindingOutputStream(baos);
bos.write(b);
bos.close();
BindingInputStream bis =
new BindingInputStream(new ByteArrayInputStream(
baos.toByteArray()));
System.out.println(bis.next());
When I try to serialize a binding which contains a Node annotated as
XSDDatatype.XSD*basicType* (e.g. XSDDatatype.XSDint,
XSDDatatype.XSDlong), I get:
Exception in thread "main" org.openjena.riot.RiotException: [line: 2,
col: 7 ] Undefined prefix: xsd
at
org.openjena.riot.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:110)
at
org.openjena.riot.system.ParserProfileBase.expandPrefixedName(ParserProfileBase.java:209)
at
org.openjena.riot.system.ParserProfileBase.create(ParserProfileBase.java:173)
at
com.hp.hpl.jena.sparql.engine.binding.BindingInputStream$IteratorTuples.moveToNext(BindingInputStream.java:194)
at
com.hp.hpl.jena.sparql.engine.binding.BindingInputStream$IteratorTuples.moveToNext(BindingInputStream.java:139)
at
org.openjena.atlas.iterator.IteratorSlotted.hasNext(IteratorSlotted.java:55)
at
org.openjena.atlas.iterator.IteratorSlotted.next(IteratorSlotted.java:64)
at
com.hp.hpl.jena.sparql.engine.binding.BindingInputStream.next(BindingInputStream.java:129)
However, when XSDDatatype.XSDinteger is used it works. Indeed, if I
have understood, data which are inserted into a dataset with tags
XSDDatatype.XSDint or XSDDatatype.XSDlong are automatically translated
to XSDDatatype.XSDinteger which uses an arbitrary precision. Is it not
possible to adapt the RIOT parser to accept default XSD types?
Kind Regards,
Laurent
Laurent,
Thanks for the test case. The code mistakenly relied on the old
FmtUtils to do formatting and that does default prefix mappings to make
things human readable. But we want machine readable.
Defaulting would solve this particular problem but require bindings
streams assume prefixes which isn't the intention.
Fix applied in svn - uses the new NodeFormatter code (which was written
but not integrated. That was the real mistake.)
Andy