<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/sem.queryResultsSerialize.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>sem.queryResultsSerialize</api:function-name><api:suggest>sem.queryresultsserialize</api:suggest><api:suggest>sem</api:suggest><api:suggest>queryresultsserialize</api:suggest><api:function-link mode="xquery" fullname="sem:query-results-serialize">/apidoc/8.0/sem:query-results-serialize.xml</api:function-link><api:function mode="javascript" name="queryResultsSerialize" lib="sem" category="Semantics" hidden="false" bucket="MarkLogic Built-In Functions" prefix="sem" namespace="http://marklogic.com/semantics" fullname="sem.queryResultsSerialize"><api:summary>This function implements the W3C SPARQL 
		Query Results format. Any value sequence returned by 
		<code xmlns="http://www.w3.org/1999/xhtml">sem:sparql</code> can be passed into this function. 
		The result will be the W3C SPARQL Results format, in either 
		XML or JSON format.
	</api:summary><api:params><api:param name="results" type="item()*"><api:param-description>
		  The results of calling a SPARQL query.
	  </api:param-description><api:param-name>results</api:param-name><api:param-type>ValueIterator</api:param-type></api:param><api:param name="options" type="xs:string*" optional="true"><api:param-description>
		One of 'xml' (default) or 'json'.
	</api:param-description><api:param-name>options</api:param-name><api:param-type>String[]</api:param-type></api:param></api:params><api:return>ValueIterator</api:return><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
var sem = require("/MarkLogic/semantics.xqy");
    
sem.queryResultsSerialize(sem.sparql( 
    'PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;\n\
    SELECT ?name WHERE { ?alum foaf:schoolHomepage &lt;http://www.ucsb.edu/&gt; .\n\
                         ?alum foaf:knows ?person .\n\
                         ?person foaf:name ?name } ')); 

=&gt;
  &lt;sparql xmlns="http://www.w3.org/2005/sparql-results#"&gt;
    &lt;head&gt;
      &lt;variable name="name"&gt;
      &lt;/variable&gt;
    &lt;/head&gt;
    &lt;results&gt;
      &lt;result&gt;
        &lt;binding name="name"&gt;
           &lt;literal datatype="http://www.w3.org/2001/XMLSchema#string"&gt;
            Karen Schouten
           &lt;/literal&gt;
        &lt;/binding&gt;
      &lt;/result&gt;
      &lt;result&gt;
        &lt;binding name="name"&gt;
           &lt;literal datatype="http://www.w3.org/2001/XMLSchema#string"&gt;
           Nick Aster
           &lt;/literal&gt;
        &lt;/binding&gt;
      &lt;/result&gt;
    &lt;/results&gt;
  &lt;/sparql&gt;
    </pre>
  </api:example></api:function></api:function-page>