ââ
Right, "Text serialization" is a very broad term.. Perhaps it is a bit
more clear to refer here to output streams (from a provider service) as
defined by a *media type*.
From what I can tell, the existing "mapping" logic for media type "json" is
done in the XQuerySerializer util. This calls the
org.exist.util.serializer.json.JSONSerializer
based on the SerializationProperty.METHOD value from the RESTXQ
implementation.
With these three components, I see a mapping workflow that involves this:
Defining a new media type constant for JSON-LD in a convenience class.
This constant could be used by a RESTXQ implementation to build an
XQueryStreamProvider that can type check whether a requested sequence is
writeable based on media type (i.e. SerializationProperty.METHOD value).
In my use case, the sequence needs to be RDF/XML (e.g. the root node
contains the xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" namespace
). If true, then the provider streams the sequence to a pre-built RDF/XML
to JSON-LD serializer, like the one previously referenced.
I am not clear on how (or if) an XQueryStreamProvider can type check a
sequence based on "contains namespace". Any suggestions?
Cheers,
Christopher
I think we might be talking at cross-purposes or certainly there is
some confusion.
Post by Christopher JohnsonSure, it is possible to write JSON-LD as text, but this is not a proper
serialization of JSON.
There is valiid JSON and then there is plain text,
and they are not the same.
In the end it is all just bytes. The XML Serializer is really
outputting "text" (compliant to the XML spec) from XML! If you wrote a
JSON-JD serializer in a similar for to the TEXTWriter, it would simply
take RDF/XML as input and output "text" (compliant to the JSON-JD
spec).
JSON is also a specification of a format of text ;-)
Post by Christopher JohnsonFor example, reading JSON as
unparsed text into a nodeset using XSLT,
fn:unparsed-text does not deliver a nodeset, it delivers an xs:string.
https://www.w3.org/TR/xpath-functions-30/#func-unparsed-text
Post by Christopher Johnsonand then sending the output to
json:contents-to-json will not yield valid JSON (at least for me).
I see that json:contents-to-json does take a node(), I am not sure how
you are going from xs:string (from output from fn:unparsed-text) to a
node() though.
I am either missing something, or this shouldn't be possible.
Post by Christopher Johnsonbut rather in
providing a valid JSON-LD serialization (and RESTXQ) output method for
any
Post by Christopher JohnsonRDF/XML that could be stored in an eXist db collection. I still suspect
that this could be a relatively common use case that is supported by
already
Yes exactly. If you have XML as input (e.g. RDF/XML) then you can
create a serializer in Java by using XMLWriter/TEXTWriter etc as
examples, as they all take XML as input and then apply a mapping to
whatever output format (in your instance you would want a mapping to
JSON-LD).
I just realised that we already have a serialization writer for a
basic mapping of XML -> JSON, see
org.exist.util.serializer.json.JSONWriter.
So you just need to create a
org.exist.util.serializer.json.JSONLDWriter which maps your XML/RDF to
your JSON-LD.
--
Adam Retter
eXist Developer
{ United Kingdom }
irc://irc.freenode.net/existdb