sem:rdf-serialize

sem:rdf-serialize(
   $triples as sem:triple*,
   [$options as xs: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

xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";

sem:rdf-serialize(
  (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

xquery version "1.0-ml"; 
 
import module namespace sem = "http://marklogic.com/semantics" 
      at "/MarkLogic/semantics.xqy";
      
sem:rdf-serialize(
    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>
    
Powered by MarkLogic Server | Terms of Use | Privacy Policy