Filtering XML data
When creating an XML data set, you specify what data to retrieve from an XML data source by mapping XML elements and attributes to data set rows and columns. To map an XML element to a row or to a column, you specify an XPath expression. XPath is a query language for accessing parts of an XML document.
Figure 12‑3 shows an example of a row mapping defined in an XML data set. The XPath expression is /library/book.
Figure 12‑3 Row mapping for an XML document
Figure 12‑4 shows an example of column mappings defined in an XML data set. The XPath expressions define the paths to the elements or attributes.
Figure 12‑4 Column mappings and the data rows returned by the XML data set
To retrieve only data rows that meet certain criteria, specify the value to search for in the row mapping XPath expression. The following XPath expression, for example, specifies that only rows where the book category is Children should be retrieved:
/library/book[@category="Children"]
When filtering data with an XPath expression, observe the following limitations:
*You can specify only one value on which to search. You cannot, for example, search for categories Children and Cooking.
*You can filter on XML attributes only, not XML elements. The XML structure in the Column Mapping page displays XML attributes with the @ symbol. In the Column Mapping page shown in Figure 12‑4, for example, @category, @lang, @name, and @country are attributes, whereas title, author, and year are elements.
For more advanced filtering capabilities, use BIRT Report Designer’s filter tool, which is described later in this section.
How to define a filter on row retrieval for XML data sets
1 In Data Explorer, double-click the XML data set to which to add a filter condition.
2 In Edit Data Set, choose Row Mapping.
3 Modify the XPath expression to specify the filter condition. The following expressions are examples of XPath filtering expressions:
/library/book[@category="Children"]
/library/book/author[@country="uk"]
The value you specify within the double quotation marks (" ") must match exactly the value in the XML document.
4 Choose Column Mapping, and edit the column mappings so that the paths are compatible with the modified row mapping. Rather than directly edit the XPath expressions, you may find it easier to delete the existing column mappings, then create new ones by selecting the element or attribute in the XML data structure and choosing the right arrow.
5 Choose Preview Results to confirm that the filter returns only rows that match the specified value.