Loading TOC...

MarkLogic 12 EA 2 Product Documentation
sem.rdfSerialize

sem.rdfSerialize(
   triples as sem.triple[],
   [options as String[]]
) as Item

Summary

This function returns a string or json or XML serialization of the provided triples.

Parameters
triples The triples to serialize.
options Parsing options. Only one of the format options is allowed. Valid option values include:
ntriple
Specify N-Triples format for output as an xs:string.
nquad
Specify N-Quads format for output as an xs:string (default).
turtle
Specify Turtle format for output as an xs:string.
rdfxml
Specify RDF/XML format for output as an element.
rdfjson
Specify JSON format for output as a json:object. Note: To serialize a JSON string, manually call xdmp:to-json on this object.
n3
Specify N3 format for output as an xs:string.
trig
Specify TriG format for output as an xs:string.
triplexml
Specify sem:triple XML format for output, either a single sem:triple element or multiple elements under a root element. If you use the triplexml option, you cannot specify a graph.

Example

const sem = require("/MarkLogic/semantics.xqy");

sem.rdfSerialize(
  (sem.triple(
     sem.iri("http://example.com/ns/directory#m"),
     sem.iri("http://example.com/ns/person#firstName"), "Michelle")));

=> 
    <http://example.com/ns/directory#m> 
	<http://example.com/ns/person#firstName> "Michelle" .
    

Example

const sem = require("/MarkLogic/semantics.xqy");

sem.rdfSerialize(
    sem.triple(sem.iri("http://example.com/ns/directory#m"),
	sem.iri("http://example.com/ns/person#firstName"),
	"Michelle")), "rdfxml");

=>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:Description rdf:about="http://example.com/ns/directory#m">
      <firstName rdf:datatype="http://www.w3.org/2001/XMLSchema#string" 
        xmlns="http://example.com/ns/person#">Michelle
      </firstName>
    </rdf:Description>
</rdf:RDF>
    

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.