mmmattos.net

Saturday, October 23, 2010

Adding ENTITIES to the generated RDF

If you have to embed typed resources as literals within an RDF, such in this example:

• <dcterms:identifier rdf:resource="&xxx;type#TheDataValue"/>

The xxx entity abbreviation must be declared outside the RDF core, in the XML DOCTYPE main node. Something like:

<!DOCTYPE rdf:RDF [
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
<!ENTITY xxx "http://someurl.org/path/path">
]>


So, the question is: how to implement this in Jena, considering Jena RDF write just outputs the RDF tree...?
As shown in this Jena file i/o how-to, Jena provides some advanced output configuration options that can control the generation of those items.
Indeed, there are two options that can be useful in generating the extra ENTITY references.

Those are:
  • showXmlDeclaration:
"If true, an XML Declaration is included in the output, if false no XML declaration is included. The default behaviour only gives an XML Declaration when asked to write to an OutputStreamWriter that uses some encoding other than UTF-8 or UTF-16. In this case the encoding is shown in the XML declaration. To ensure that the encoding attribute is shown in the XML declaration either:
Set this option to true and use the write(Model,Writer,String) variant with an appropriate OutputStreamWriter.
Or set this option to false, and write the declaration to an OutputStream before calling write(Model,OutputStream,String)."
  • showDoctypeDeclaration:
"If true, an XML Doctype declaration is included in the output. This declaration includes a !ENTITY declaration for each prefix mapping in the model, and any attribute value that starts with the URI of that mapping is written as starting with the corresponding entity invocation."


No comments:

Post a Comment