Skip to content

Instantly share code, notes, and snippets.

@nishantsingh1
nishantsingh1 / GoodUri.java
Last active August 29, 2015 14:16
Example showing XCC with a URI which has been encoded safely
import com.marklogic.xcc.*;
import com.marklogic.xcc.exceptions.RequestException;
import com.marklogic.xcc.exceptions.XccConfigException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.text.MessageFormat;
@nishantsingh1
nishantsingh1 / BadUri.java
Last active August 29, 2015 14:16
Example showing XCC with a URI which has not been encoded
import com.marklogic.xcc.*;
import com.marklogic.xcc.exceptions.RequestException;
import com.marklogic.xcc.exceptions.XccConfigException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.MessageFormat;
/**
* Example showing XCC with a URI which has not been encoded
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
import schema "http://www.example.org/uri" at "/D/urisschema/uri.xsd";
(:
this will validate against the specified schema, and will fail
if the schema does not exist (or if it is not valid according to
the schema)
:)
@nishantsingh1
nishantsingh1 / uri.xsd
Created March 9, 2015 08:09
a sample schema with a xs:anyURI type
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/uri"
xmlns:tns="http://www.example.org/uri" elementFormDefault="qualified">
<element name="simpleuri" type="anyURI" />
</schema>
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
sem:rdf-insert(
sem:triple( sem:iri("http://dbpedia.org/resource/Michael_Jackson"),
sem:iri("http://dbpedia.org/ontology/associatedBand"),
sem:iri("http://dbpedia.org/resource/The_Jackson_5")
)
)
@nishantsingh1
nishantsingh1 / sem_query_results_serialize_with_json_output.xqy
Created July 5, 2016 09:58
Example of sem:query-results-serialize with 'json' as result format
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
sem:query-results-serialize(sem:sparql('
PREFIX db: <http://dbpedia.org/resource/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?s
WHERE { ?s onto:associatedBand db:The_Jackson_5}
@nishantsingh1
nishantsingh1 / sem_query_results_serialize_with_xml_output.xqy
Created July 5, 2016 09:58
Example of sem:query-results-serialize with 'xml' as result format
xquery version "1.0-ml";
import module namespace sem = "http://marklogic.com/semantics"
at "/MarkLogic/semantics.xqy";
sem:query-results-serialize(sem:sparql('
PREFIX db: <http://dbpedia.org/resource/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?s
WHERE { ?s onto:associatedBand db:The_Jackson_5}
@nishantsingh1
nishantsingh1 / output_sem_query_results_serialize_with_xml_ml8.xml
Created July 5, 2016 10:14
Output from ML 8.0-5.4 - sem:query-results-serialize with 'xml'
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="s">
</variable>
</head>
<results>
<result>
<binding name="s">
<uri>http://dbpedia.org/resource/Michael_Jackson</uri>
</binding>
@nishantsingh1
nishantsingh1 / output_sem_query_results_serialize_with_xml_ml7.xml
Last active July 5, 2016 10:15
Output from ML 7.0.5.3 - sem:query-results-serialize with 'xml'
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="s">
</variable>
</head>
<results>
<result>
<binding name="s">
<uri>http://dbpedia.org/resource/Michael_Jackson
</uri>
@nishantsingh1
nishantsingh1 / byExample_company.js
Created November 15, 2016 08:41
Node.js example 2: a simple QBE for range queries using filtered search and sorting on company property in descending order
var marklogic = require("marklogic");
var conn = require("./env.js").connection;
//create DatabaseClient
var db = marklogic.createDatabaseClient(conn);
var q = marklogic.queryBuilder;
db.documents.query(
q.where(
q.byExample(