Skip to content

XML Query Data Source

This data source executes an XQuery expression on an XML database and returns the result as a list of values.

Due to the flexibility of XQuery, this data source can be utilized to query and transform XML data in a multitude of ways.

Query parameters can be specified using the Parameter elements, and the query itself is defined within the Query element.

The ItemXPath element designates the path to the items within the XML data that will be returned as the result of the query.

Example

The following example demonstrates a straightforward query that retrieves contacts from an XML database. The query filters the contacts based on a search name and relation type and returns the contacts sorted by display name.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
<XmlQueryDataSource TextFormat="{{DisplayName}}" ValueFormat="{{Id}}" Enabled="True">
    <Mappings/>
    <ItemXPath><![CDATA[Contract]]></ItemXPath>
    <Parameters>
        <Parameter Name="filter"><![CDATA[Filter/SearchName]]></Parameter>
        <Parameter Name="typeId"><![CDATA[Filter/RelationType/Id]]></Parameter>
    </Parameters>
    <Query><![CDATA[

for $c in Contact
where ($filter='' or contains(lower-case($c/SearchName),lower-case($filter)))
    and ($typeId='' or $c/RelationType/Id=$typeId)
order by $c/DisplayName
return $c

]]></Query>
</XmlQueryDataSource>

In this configuration:

  • TextFormat is set to {{DisplayName}}, indicating that the DisplayName element within the XML result will be used for display text.
  • ValueFormat is set to {{Id}}, specifying that the Id element will be used as the underlying value.
  • Enabled is set to True, activating the data source.
  • Mappings is empty, meaning no additional mappings are specified.
  • ItemXPath is set to <![CDATA[Contract]]>, indicating the path to the elements that will be processed as items.
  • The Parameters element defines two parameters:
    • filter, which is mapped to the Filter/SearchName element in the data model.
    • typeId, which is mapped to the Filter/RelationType/Id element in the data model.
  • The Query element contains the XQuery expression which:
    • Iterates over all Contact elements.
    • Filters contacts based on the filter and typeId parameters, using a case-insensitive search on the SearchName element.
    • Orders the results by the DisplayName element.
    • Returns each matching Contact element.