Share via


Working with results from multiple SourceTypes

Remember that the prefixing of the Count and Offset parameters is necessary because you can specify multiple SourceTypes. The URL to make a request for both the Web and Image SourceTypes might look like this: http://api.search.live.net/xml.aspx?Appid=<AppID>&query=sushi&sources=web+image.

Figure 3 shows results that this request might return. Note that, in this example, we have contracted the Web and Image results, as indicated by + <web:Results> and + <mms:Results>. mms means "multimedia SourceType."

  <?xml version="1.0" encoding="utf-8" ?> 
  <?pageview_candidate ?> 
- <SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.0">
- <Query>
  <SearchTerms>sushi</SearchTerms> 
  </Query>
- <web:Web xmlns:web="http://schemas.microsoft.com/LiveSearch/2008/04/XML/web">
  <web:Total>12400000</web:Total> 
  <web:Offset>0</web:Offset> 
+ <web:Results>
  </web:Web>
- <mms:Image xmlns:mms="http://schemas.microsoft.com/LiveSearch/2008/04/XML/multimedia">
  <mms:Total>3580000</mms:Total> 
  <mms:Offset>0</mms:Offset> 
+ <mms:Results>
  </mms:Image>
  </SearchResponse>

Figure 3: Multiple SourceTypes Results

Note that the Image element has its own namespace URI. It also includes Total and Offset child elements, but qualified with the mms namespace prefix. The third child element of any XML results set is an element with a local name of Results – again, qualified by its parent namespace URI.

When you are processing the results of a multiple-SourceType request, you must determine the order of results dynamically; SourceTypes are not necessarily returned in a particular order.

The Results element is the parent element for a number of child elements, each of which represents a particular result from a particular SourceType. These child elements all have SourceType-specific names, such as WebResult and ImageResult. You can parse these results using the XML processing API of your choice (which will be determined largely by your programming language and runtime choice).