sem:graph-insert( $graphname as sem:iri, $triples as sem:triple*, [$permissions as item()*], [$collections as xs:string*], [$quality as xs:int?], [$forest-ids as xs:unsignedLong*] ) as xs:string*
This function inserts triples into a named graph, creating the graph if necessary. It also creates the graph metadata for the graph specified by the "graphname" option. This is an update function that returns document IDs.
graph-insert
in the context of SPARQL Update can result in undefined behavior.
xquery version "1.0-ml"; import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy"; sem:graph-insert(sem:iri('bookgraph'), sem:triple(sem:iri('urn:isbn:9780080540160'), sem:iri('http://purl.org/dc/elements/1.1/title'), "Query XML,XQuery, XPath, and SQL/XML in context")) => /triplestore/2c78915c5854b0f8.xml
xquery version "1.0-ml"; import module namespace sem = "http://marklogic.com/semantics" at "/MarkLogic/semantics.xqy"; let $string := ' <urn:isbn:006251587X> <http://purl.org/dc/elements/1.1/creator> <http://www.w3.org/People/Berners-Lee/card#i> . <urn:isbn:006251587X> <http://purl.org/dc/elements/1.1/title> "Weaving the Web" . <http://www.w3.org/People/Berners-Lee/card#i> <http://www.w3.org/2006/vcard/title>"Director" .' let $triples := sem:rdf-parse($string, "ntriple") let $i := sem:graph-insert(sem:iri("bookgraph"), $triples, (), "smGraph") return(fn:collection("smGraph")//sem:triple); => (: returns triples as nodes :) <sem:triple xmlns:sem="http://marklogic.com/semantics"> <sem:subject>urn:isbn:006251587X</sem:subject> <sem:predicate>http://purl.org/dc/elements/1.1/creator</sem:predicate> <sem:object>http://www.w3.org/People/Berners-Lee/card#i</sem:object> </sem:triple> <sem:triple xmlns:sem="http://marklogic.com/semantics"> <sem:subject>urn:isbn:006251587X</sem:subject> <sem:predicate>http://purl.org/dc/elements/1.1/title</sem:predicate> <sem:object datatype="http://www.w3.org/2001/XMLSchema#string"> Weaving the Web</sem:object> </sem:triple> <sem:triple xmlns:sem="http://marklogic.com/semantics"> <sem:subject>http://www.w3.org/People/Berners-Lee/card#i</sem:subject> <sem:predicate>http://www.w3.org/2006/vcard/title</sem:predicate> <sem:object datatype="http://www.w3.org/2001/XMLSchema#string"> Director</sem:object> </sem:triple> <sem:triple xmlns:sem="http://marklogic.com/semantics"> <sem:subject>urn:isbn:9780080540160</sem:subject> <sem:predicate>http://purl.org/dc/elements/1.1/title</sem:predicate> <sem:object datatype="http://www.w3.org/2001/XMLSchema#string"> Query XML,XQuery, XPath, and SQL/XML in context</sem:object> </sem:triple>
Stack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.