XML Query Syntax for XML Report Data (SSRS)

In Reporting Services, you can create datasets for XML data sources. After you define a data source, you create a query for the dataset. Depending on the type of XML data pointed to by the data source, you create the dataset query by including an XML Query or an element path. An XML Query starts with a <Query> tag and includes namespaces and XML elements that vary depending on the data source. An element path is namespace-independent and specifies which nodes and node attributes to use from the underlying XML data with an XPath-like syntax. For more information about element paths, see Element Path Syntax for XML Report Data (SSRS).

You can create an XML data source for the following types of XML data:

  • Xml documents pointed to by a URL using http protocol

  • Web service endpoints that return XML data

  • Embedded XML data

    How you specify an XML Query or an element path depends on the type of XML data.

    For an XML document, the XML Query is optional. If it is included, it can contain an optional XML ElementPath. The value of the XML ElementPath uses the element path syntax. You include the XML Query and XML ElementPath to process namespaces correctly when it is needed by the XML data from the data source.

    For a Web service endpoint pointed to by a connection string URL, the XML Query defines either the Web service method, the SOAP action, or both. The XML data provider creates a Web service request that retrieves XML data to use for the report.


When a Web service namespace includes a forward slash (/) character, include both the Web service method and the SOAP action so that the XML data processing extension can derive the namespace correctly.

For an embedded XML document, the XML Query defines the embedded XML data to use, includes optional namespaces, and contains an optional XML ElementPath..

Specifying Query Parameters for XML Data

You can specify query parameters for XML documents.

  • For URL requests, the query parameters are included as standard URL parameters.

  • For Web service requests, query parameters are passed to the Web service method. To define a query parameter, use the Parameters page of the Dataset Properties dialog box. For more information, see Dataset Properties Dialog Box, Parameters.


The examples in the following table illustrate how to retrieve data from the Report Server Web service, an XML document, and embedded XML data.

XML data source Query example
Web service XML data from ListChildren method. <Query>

<Method Name="ListChildren" Namespace="http://schemas.microsoft.com/sqlserver/2005/06/30/reporting/reportingservices" />

Web service XML data from SoapAction. <Query xmlns=namespace>


XML Document or embedded XML data that uses namespaces.

Query element specifying namespaces for an element path.
<Query xmlns:es="http://schemas.microsoft.com/StandardSchemas/ExtendedSales">


Embedded XML document. <Query>



<Customer ID="1">Bobby</Customer>



<ElementPath>Customer {@}</ElementPath>

XML document that uses default. No query.

The element path is derived from the XML document itself and is namespace-independent.

The first Web service example lists the contents of the report server that uses the ListChildren method. To run this query, you must create a new data source and set the connection string to http://localhost/reportserver/reportservice2006.asmx. The ListChildren method takes two parameters: Item and Recursive. Set the default value for Item to / and Recursive to 1.

Specifying Namespaces

Use the XML Query element to specify the namespaces that are used in the XML data from the data source. The following XML query uses the namespace sales. The XML ElementPath nodes for sales:LineItems and sales:LineItem use the namespace sales.

<Query xmlns:sales=  

To specify the data provider namespace so that the default namespace remains empty, use xmldp. This is shown in the following example.


The following examples use the XML document DPNamespace.xml, which is provided for illustration after the table. This table shows two examples of XML ElementPath syntax that includes namespace prefixes.

XML Query Element Resulting fields in the dataset
<Query/> Value A: http://schemas.microsoft.com/...

Value B: http://schemas.microsoft.com/...

Value C: http://schemas.microsoft.com/...
<xmldp:Query xmlns:xmldp="http://schemas.microsoft.com/sqlserver/2005/02/reporting/XmlDPQuery" xmlns:ns="http://schemas.microsoft.com/...">

<xmldp:ElementPath>Root {}/ns:Element2/Node</xmldp:ElementPath>

Value D

Value E

Value F

XML document: DPNamespace.xml

You can copy this XML and save it to a URL available for Report Designer to use as an XML data source: for example, http://localhost/DPNamespace.xml.

<Root xmlns:ns="http://schemas.microsoft.com/...">  
      <Node>Value A</Node>  
      <Node>Value B</Node>  
      <Node>Value C</Node>  
      <Node>Value D</Node>  
      <Node>Value E</Node>  
      <Node>Value F</Node>  

See Also

XML Connection Type (SSRS)
Reporting Services Tutorials (SSRS)