Developer Console

Querying XML (Fire App Builder)

When you set up your recipes, you used XML query syntax for the query parameter. XML queries use XPath expressions. You can learn more about the XPath syntax here. You can also test out your XPath expressions using this XPath Tester / Evaluator.

Once you get the result from XPath, you use matchList selectors to select specific elements in the query result. The matchList selectors don't use XPath syntax but rather a custom Amazon syntax to target the right elements. The purpose of the matchList selector is to correlate an element in your feed with the Fire App Builder content model so that the right item can be displayed in the Fire App Builder UI.

The examples on this page demonstrate a variety of both XPath queries and matchList selectors. In each example, first a query is used to target specific elements from your feed. Then a matchList parameter is used to select the elements from the query's returns.

With the matchList parameter, there's not an evaluator (as there is with XPath) where you can plug in the syntax and see the result. The only way is to look at how your app builds in Android Studio.

Querying for Categories

Example 1: Basic XPath Syntax

This example shows how to target elements using basic XPath syntax.

Suppose your XML document looks like this:

<doc>
     <title>My catagory title</title>
     <p pid="1">My category</p>
     <p>my category</p>
 </doc>

A query for doc/title would result in the following:

Element='<title>My category</title>'

A query for doc/p[2] would result in the following:

Element='<title>My category</title>'

A query for doc/p[@pid="1"] would result in the following:

Element='<p pid="1">My category</p>'

Example 2: Retrieving the Category

This example shows how to retrieve the categories and items from an XML feed using XQuery syntax.

Here's a more complex XML feed:

<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">

  <channel>
    <title>Generic mrss feed</title>
    <link>http://www.developer.amazon.com/</link>
    <description>Generic mrss data</description>
    <item>
      <id>1</id>
      <title>Nullamtus</title>
      <link>http://www.developer.amazon.com/</link>
      <pubdate>Wed, 14 Jan 2015 00:36:00 +0000</pubdate>
      <description>Sed a sagittis urna, a fermentum ligula. In sagittis sagittis libero, ut tincidunt sapien egestas.</description>
      <image>https://raw.githubusercontent.com/amzn/web-app-starter-kit-for-fire-tv/master/src/common/assets/images/l1.jpg</image>
      <category>Lifestyle</category>
    </item>
    <item>
      <id>2</id>
      <title>Ut at augue</title>
      <link>http://www.developer.amazon.com/</link>
      <pubdate>Wed, 14 Jan 2015 00:36:00 +0000</pubdate>
      <description>Phasellus vulputate tellus vitae volutpat viverra. Praesent posuere rutrum erat nec suscipit. Fusce interdum porta porta. Integer vulputate malesuada dictum.</description>
      <image>https://raw.githubusercontent.com/amzn/web-app-starter-kit-for-fire-tv/master/src/common/assets/images/l2.jpg</image>
      <category>Travel</category>
    </item>
    <item>
      <id>3</id>
      <title>Quisque porttitor augue</title>
      <link>http://www.developer.amazon.com/</link>
      <pubdate>Wed, 14 Jan 2015 00:36:00 +0000</pubdate>
      <description>Pellentesque vel metus sem. Aenean porta elementum sagittis.</description>
      <image>https://raw.githubusercontent.com/amzn/web-app-starter-kit-for-fire-tv/master/src/common/assets/images/l3.jpg</image>
      <category>Sports</category>
    </item>

  </channel>
</rss>

A query for rss/channel/item/category/text() would result in the following:

Text='Lifestyle'
Text='Travel'
Text='Sports'

A query for /rss/channel/item would result in the following:

Element='<item>
      <title>Taylor Swift</title>
      <guid isPermaLink="false">1</guid>
      <pubDate>Mon, 08 Dec 2014 22:55:16 GMT</pubDate>
      <category>News</category>
      <media:content xmlns:media="http://search.yahoo.com/mrss/"
                  type="jpg"
                  url="http://samples.screenfeed.com/1">
        <media:title type="plain">1080x1920 - English - with caption</media:title>
        <media:credit>© 2014 Thomson Reuters</media:credit>
        <media:thumbnail type="jpg"
                       url="http://samples.screenfeed.com/public/us-news-in-pictures/1080x1920/h9xnRIN9CUGiTWNQBBrjOw-1080x1920h-1"/>
      </media:content>
    </item>'
Element='<item>
      <title>Melanie Martinez</title>
      <guid isPermaLink="false">1</guid>
      <pubDate>Mon, 1 Dec 2014 12:35:56 GMT</pubDate>
      <category>Trending</category>
      <media:content xmlns:media="http://search.yahoo.com/mrss/"
                  type="jpg"
                  url="http://samples.screenfeed.com/2">
        <media:title type="plain">1080x1920 - English - with caption</media:title>
        <media:credit>© 2014 Thomson Reuters</media:credit>
        <media:thumbnail type="jpg"
                       url="http://samples.screenfeed.com/public/us-news-in-pictures/1080x1920/h9x4985398UGiTWNQBBrjOw-1080x1920h-2"/>
      </media:content>
    </item>'