<export><workspace name="TDE Prague Demo"><query name="1. Insert simple document" focus="false" listorder="1" taborder="1" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="xquery">(:
  Insert a simple XML document in the database.
  We'll create a SQL view over this document.
:)

xdmp:document-insert(
     "/soccer/match/1234567.xml",
&lt;match&gt;
 &lt;id&gt;1234567&lt;/id&gt;
 &lt;docUri&gt;/match/1234567.xml&lt;/docUri&gt;
 &lt;match-date&gt;2016-01-12&lt;/match-date&gt;
 &lt;league&gt;Premier&lt;/league&gt;
 &lt;teams&gt;
   &lt;home&gt;Bournemouth&lt;/home&gt;
   &lt;away&gt;West Ham United&lt;/away&gt;
 &lt;/teams&gt;
 &lt;score&gt;
   &lt;home&gt;1&lt;/home&gt;
   &lt;away&gt;3&lt;/away&gt;
 &lt;/score&gt;
 &lt;abstract&gt;Dimitri Payet inspired a West Ham comeback to secure victory over Bournemouth.&lt;/abstract&gt;
 &lt;report&gt;Harry Arter had given the hosts the lead with a 25-yard strike. ... &lt;/report&gt;
&lt;/match&gt; ,
 xdmp:default-permissions(),
 "TDE-EA"
 )

</query><query name="2. Insert the template" focus="false" listorder="2" taborder="2" active="true" database="15915168341080375244" server="12522660287106707310" database-name="Schemas" server-name="App-Services" mode="xquery">(:
  Insert the Template.
  The function tde:template-insert() will validate the template; insert it into the Schemas database; and assign the special collection "http://marklogic.com/xdmp/tde"
:)

import module "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";

let $my-first-TDE:=
&lt;template xmlns="http://marklogic.com/xdmp/tde"&gt;
  &lt;context&gt;/match&lt;/context&gt;
  &lt;rows&gt;
    &lt;row&gt;
      &lt;schema-name&gt;soccer&lt;/schema-name&gt;
      &lt;view-name&gt;matches&lt;/view-name&gt;
      &lt;columns&gt;
        &lt;column&gt;
          &lt;name&gt;id&lt;/name&gt;
          &lt;scalar-type&gt;long&lt;/scalar-type&gt;
          &lt;val&gt;id&lt;/val&gt;
          &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
        &lt;/column&gt;
        &lt;column&gt;
          &lt;name&gt;document&lt;/name&gt;
          &lt;scalar-type&gt;string&lt;/scalar-type&gt;
          &lt;val&gt;docUri&lt;/val&gt;
          &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
        &lt;/column&gt;
        &lt;column&gt;
          &lt;name&gt;date&lt;/name&gt;
          &lt;scalar-type&gt;date&lt;/scalar-type&gt;
          &lt;val&gt;match-date&lt;/val&gt;
          &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
        &lt;/column&gt;
        &lt;column&gt;
          &lt;name&gt;league&lt;/name&gt;
          &lt;scalar-type&gt;string&lt;/scalar-type&gt;
          &lt;val&gt;league&lt;/val&gt;
          &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
        &lt;/column&gt;
      &lt;/columns&gt;
    &lt;/row&gt;
  &lt;/rows&gt;
&lt;/template&gt;

return tde:template-insert(
 "/test/my-first-TDE.xml" ,
 $my-first-TDE ,
 xdmp:default-permissions() ,
 "TDE-EA"
 )
 </query><query name="3. Show the view" focus="false" listorder="3" taborder="3" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="xquery">(:
  Show the view you just created.
:)

 tde:get-view ( "soccer", "matches" )
 </query><query name="4. Simple SQL query" focus="false" listorder="4" taborder="4" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="sql">-- simple SQL query

select *
from matches
</query><query name="5. Insert second document" focus="false" listorder="5" taborder="5" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="xquery">(:
  Insert a new document that has the same kind of information, but in a different format.
:)

xdmp:document-insert(
 "/soccer/match/4485.xml",
&lt;match id="4485"&gt;
 &lt;meta&gt;
   &lt;document-location&gt;/match/4485.xml&lt;/document-location&gt;
   &lt;event&gt;
     &lt;date&gt;
       &lt;day&gt;09&lt;/day&gt;
       &lt;month&gt;01&lt;/month&gt;
       &lt;year&gt;16&lt;/year&gt;
     &lt;/date&gt;
     &lt;competition&gt;FA Cup&lt;/competition&gt;
   &lt;/event&gt;
 &lt;/meta&gt;
 &lt;teams&gt;
   &lt;home&gt;West Ham United&lt;/home&gt;
   &lt;away&gt;Wolverhampton Wanderers&lt;/away&gt;
 &lt;/teams&gt;
 &lt;score&gt;
   &lt;home&gt;1&lt;/home&gt;
   &lt;away&gt;0&lt;/away&gt;
 &lt;/score&gt;
 &lt;abstract&gt;West Ham progressed into the fourth round of the FA Cup.&lt;/abstract&gt;
 &lt;report&gt;Nikica Jelavic scored in the 85th minute when he produced a great low-angled half-volley. ...
 &lt;/report&gt;
&lt;/match&gt; ,
 xdmp:default-permissions(),
 "TDE-EA"
 )
 </query><query name="6. Insert second template" focus="false" listorder="6" taborder="6" active="true" database="15915168341080375244" server="12522660287106707310" database-name="Schemas" server-name="App-Services" mode="xquery">(:
  Insert a new Template.
:)

import module "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";

let $my-second-TDE:=
&lt;template xmlns="http://marklogic.com/xdmp/tde"&gt;
 &lt;context&gt;/match&lt;/context&gt;
 &lt;rows&gt;
   &lt;row&gt;
     &lt;schema-name&gt;soccer&lt;/schema-name&gt;
     &lt;view-name&gt;matches&lt;/view-name&gt;
     &lt;columns&gt;
       &lt;column&gt;
         &lt;name&gt;id&lt;/name&gt;
         &lt;scalar-type&gt;long&lt;/scalar-type&gt;
         &lt;val&gt;@id&lt;/val&gt;
         &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
       &lt;/column&gt;
       &lt;column&gt;
         &lt;name&gt;document&lt;/name&gt;
         &lt;scalar-type&gt;string&lt;/scalar-type&gt;
         &lt;val&gt;meta/document-location&lt;/val&gt;
         &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
       &lt;/column&gt;
       &lt;column&gt;
         &lt;name&gt;date&lt;/name&gt;
         &lt;scalar-type&gt;date&lt;/scalar-type&gt;
         &lt;val&gt;concat( '20', meta/event/date/year, '-', meta/event/date/month, '-', meta/event/date/day )&lt;/val&gt;
         &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
       &lt;/column&gt;
       &lt;column&gt;
         &lt;name&gt;league&lt;/name&gt;
         &lt;scalar-type&gt;string&lt;/scalar-type&gt;
         &lt;val&gt;meta/event/competition&lt;/val&gt;
         &lt;invalid-values&gt;ignore&lt;/invalid-values&gt;
       &lt;/column&gt;
     &lt;/columns&gt;
   &lt;/row&gt;
 &lt;/rows&gt;
&lt;/template&gt;

return tde:template-insert(
 "/test/my-second-TDE.xml" ,
 $my-second-TDE,
 xdmp:default-permissions(),
 "TDE-EA"
 )
 </query><query name="7. Combination query" focus="false" listorder="7" taborder="7" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="xquery">(:
 # combination SQL query from XQuery
:)
 
xdmp:sql(
  "select 
    id, league 
    from matches
    where 
      date &gt; cast ('2016-01-10' as date)"
    ,
  (),
  (),
  cts:word-query('Harry Arter')
  )

</query><query name="Cleanup - Schemas" focus="false" listorder="11" taborder="" active="false" database="15915168341080375244" server="12522660287106707310" database-name="Schemas" server-name="App-Services" mode="xquery">(:
  Delete all the templates we created in this exercise, using the collection name.
  NOTE: if you are running this from Query Console, set "Database:" to "Schemas".
:)

xdmp:collection-delete( "TDE-EA" )
</query><query name="Cleanup - Documents" focus="false" listorder="12" taborder="" active="false" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="xquery">(:
  Delete all the templates we created in this exercise, using the collection name.
:)

xdmp:collection-delete( "TDE-EA" )
</query><query name="8. Insert Triples Template" focus="true" listorder="8" taborder="8" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="xquery">(:
  Insert the Template.
  Put it in a collection "TDE-EA" that we'll use for cleanup later on.
  NOTE: tde:template-insert() will validate the Template, insert it in the Schemas database, and add the special TDE collection.
:)

import module "http://marklogic.com/xdmp/tde" at "/MarkLogic/tde.xqy";

let $my-first-triples-TDE:=
&lt;template xmlns="http://marklogic.com/xdmp/tde"&gt;
  &lt;context&gt;/match/id&lt;/context&gt;
  &lt;vars&gt;
    &lt;var&gt;
      &lt;name&gt;EX&lt;/name&gt;
      &lt;val&gt;"http://example.org/ex#"&lt;/val&gt;
    &lt;/var&gt;
  &lt;/vars&gt;
  &lt;triples&gt;
    &lt;triple&gt;
      &lt;subject&gt;
        &lt;val&gt;sem:iri( xdmp:node-uri(.) )&lt;/val&gt;
      &lt;/subject&gt;
      &lt;predicate&gt;
        &lt;val&gt;sem:iri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")&lt;/val&gt;
      &lt;/predicate&gt;
      &lt;object&gt;
        &lt;val&gt;sem:iri( $EX || "match" )&lt;/val&gt;
      &lt;/object&gt;
    &lt;/triple&gt;
    &lt;triple&gt;
      &lt;subject&gt;
        &lt;val&gt;sem:iri( xdmp:node-uri(.) )&lt;/val&gt;
      &lt;/subject&gt;
      &lt;predicate&gt;
        &lt;val&gt;sem:iri( $EX || "hasID" )&lt;/val&gt;
      &lt;/predicate&gt;
      &lt;object&gt;
        &lt;val&gt;xs:integer( . )&lt;/val&gt;
      &lt;/object&gt;
    &lt;/triple&gt;
    &lt;triple&gt;
      &lt;subject&gt;
        &lt;val&gt;sem:iri( xdmp:node-uri(.) )&lt;/val&gt;
      &lt;/subject&gt;
      &lt;predicate&gt;
        &lt;val&gt;sem:iri( $EX || "hasDate" )&lt;/val&gt;
      &lt;/predicate&gt;
      &lt;object&gt;
        &lt;val&gt;xs:date( ../match-date )&lt;/val&gt;
      &lt;/object&gt;
    &lt;/triple&gt;
    &lt;triple&gt;
      &lt;subject&gt;
        &lt;val&gt;sem:iri( xdmp:node-uri(.) )&lt;/val&gt;
      &lt;/subject&gt;
      &lt;predicate&gt;
        &lt;val&gt;sem:iri( $EX || "hasLeague" )&lt;/val&gt;
      &lt;/predicate&gt;
      &lt;object&gt;
        &lt;val&gt;xs:string( ../league )&lt;/val&gt;
      &lt;/object&gt;
    &lt;/triple&gt;
  &lt;/triples&gt;
&lt;/template&gt; 

return tde:template-insert(
 "/test/my-first-triples-TDE.xml" ,
 $my-first-triples-TDE,
 xdmp:default-permissions(),
 "TDE-EA"
 )
 </query><query name="9. Simple SPARQL query" focus="false" listorder="9" taborder="9" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="sparql">#
# simple SPARQL query using the SPARQL mode in Query Console
#
 
select *
{
  ?s a &lt;http://example.org/ex#match&gt; .
  ?s ?p ?o
}
</query><query name="10. Combination SPARQL query" focus="false" listorder="10" taborder="10" active="true" database="3014505934945803333" server="12522660287106707310" database-name="tde" server-name="App-Services" mode="xquery">(:
 # combination SQL query from XQuery
:)
 
sem:sparql("
prefix xs: &lt;http://www.w3.org/2001/XMLSchema#&gt;

select ?doc ?id ?league ?date
{
  ?doc &lt;http://example.org/ex#hasID&gt; ?id;
       &lt;http://example.org/ex#hasLeague&gt; ?league;
       &lt;http://example.org/ex#hasDate&gt; ?date .
  filter( ?date &gt; '2016-01-10'^^xs:date )
}" ,
(), (), cts:word-query("Dimitri Payet")
)

</query></workspace></export>
