<?xml version="1.0" encoding="UTF-8"?><api:function-page xml:base="/apidoc/8.0/cts.elementQuery.xml" generated="2015-10-07T16:36:00.016766-07:00" mode="javascript" xmlns:api="http://marklogic.com/rundmc/api"><api:function-name>cts.elementQuery</api:function-name><api:suggest>cts.elementquery</api:suggest><api:suggest>cts</api:suggest><api:suggest>elementquery</api:suggest><api:function-link mode="xquery" fullname="cts:element-query">/apidoc/8.0/cts:element-query.xml</api:function-link><api:function mode="javascript" name="elementQuery" type="builtin" lib="cts" category="SearchBuiltins" subcategory="cts:query Constructors" hidden="false" bucket="MarkLogic Built-In Functions" prefix="cts" namespace="http://marklogic.com/cts" fullname="cts.elementQuery"><api:summary>
  Returns a <code xmlns="http://www.w3.org/1999/xhtml">cts:query</code> matching elements by name
  with the content constrained by the given <code xmlns="http://www.w3.org/1999/xhtml">cts:query</code> in the
  second parameter.
  Searches for matches in the specified element and all of its descendants.
  If the specified query in the second parameter has any
  <code xmlns="http://www.w3.org/1999/xhtml">cts:element-attribute-*-query</code> constructors, it will search
  attributes directly on the specified element and attributes on any
  descendant elements (see the 
  <a href="#eq2js" class="javascript" xmlns="http://www.w3.org/1999/xhtml">second example</a> below).
</api:summary><api:params><api:param name="element-name" type="xs:QName*"><api:param-description>
    One or more element QNames to match.
    When multiple QNames are specified,
    the query matches if any QName matches.
  </api:param-description><api:param-name>element-name</api:param-name><api:param-type>xs.QName[]</api:param-type></api:param><api:param name="query" type="cts:query"><api:param-description>
    A query for the element to match.  If a string
   is entered, the string is treated as a <code xmlns="http://www.w3.org/1999/xhtml">cts:word-query</code> of the
   specified string.
  </api:param-description><api:param-name>query</api:param-name><api:param-type>cts.query</api:param-type></api:param></api:params><api:return>cts.elementQuery</api:return><api:usage>
  <p xmlns="http://www.w3.org/1999/xhtml">Enabling both the word position and element position indexes 
  ("word position" and "element word position" in the database configuration 
  screen of the Admin Interface) will speed up query performance for many 
  queries that use <code>cts:element-query</code>. The  position indexes 
  enable MarkLogic Server to eliminate many false-positive results, which can 
  reduce disk I/O and processing, thereby speeding the performance of many 
  queries.  The amount of benefit will vary depending on your data.</p>
  <p xmlns="http://www.w3.org/1999/xhtml">You can query for the existence of an element by specifying an empty 
   
  <a href="./cts.andQuery" class="javascript"><code>cts.andQuery</code></a> as 
  the second parameter. For example, the following will match any instance
  of the specified element:</p>
  
  <blockquote class="javascript" xmlns="http://www.w3.org/1999/xhtml">
  <pre xml:space="preserve">
  cts.elementQuery(xs.QName("my-element"),
    cts.andQuery( [] )) 
  </pre></blockquote> 
</api:usage><api:example class="javascript"><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">
  cts.search(cts.elementQuery(
      xs.QName("function"),
      "MarkLogic Corporation"))

  =&gt; .. relevance-ordered sequence of 'module' elements
  ancestors (or self) of elements with QName 'function'
  and text content containing the phrase 'MarkLogic
  Corporation'.
</pre></api:example><api:example class="javascript"><a id="eq2js" xmlns="http://www.w3.org/1999/xhtml"></a><pre xml:space="preserve" xmlns="http://www.w3.org/1999/xhtml">

var x = xdmp.unquote('&lt;a attr="something"&gt;hello&lt;/a&gt;');
cts.contains(x, cts.elementQuery(xs.QName("a"),
   cts.andQuery((
     cts.elementAttributeWordQuery(xs.QName("a"),
         xs.QName("attr"), "something"),
     cts.wordQuery("hello")))));
// returns true
</pre></api:example></api:function></api:function-page>