Using XML (Bing, Version 2)

The Bing XML interface is an HTTP GET interface which accepts search requests in URL format and returns search results in XML format.

Sending a Request in URL Format

In order to use the XML interface, you need to know is how to submit a search request in URL format.

When a search request is submitted in URL format, each URL parameter presents a field in the search request. A simple search request that returns a Web result and a Spell result could look like this:

http://api.bing.net/xml.aspx?AppId= YOUR_APPID &Version=2.2&Market=en-US&Query=testign&Sources=web+spell&Web.Count= 1

AppId, Version, Market, Query, and Sources are the first-level fields of SearchRequest object, which can be directly specified as URL parameters. Simple types like AppId can be specified by the syntax Field**=Value. However, array types such as Sources, the list of SourceType enumerations, should be separated by +. Thus, the syntax will look like Field=Value1+Value2++ValueN. In addition, to specify the value of fields in a structure type, like Count in WebRequest, the . operator is used to access sub-fields with the syntax Field.SubField=**Value.

Note: Arrays of arrays or structures are not supported in the request interface of Bing API 2.0. For arrays of strings, space in each string must be encoded. For example, use %20 as opposed to +.

For details of search request and response objects, refer to the following topics:

Note: For Silverlight and Flash developers, cross domain access policy for Bing API 2.0 is published in the following URLs:

Using XmlType

For the XML interface, there is an interface specific parameter XmlType, which can control the flavor of XML interface. If ElementBased enumeration is specified, each field will be rendered as a separated tag. If AttributeBased enumeration is specified, all simple type fields will be rendered as attributes instead of elements. The default value is ElementBased.

The following sections give an example request and response for each of these options.

ElementBased Enumeration Example

Request

http://api.bing.net/xml.aspx?AppId = [YOUR_APPID] &Verstion=2.2&Market=en-US&Query=testign&Sources=web+spell&web.count=1&xmltype=elementbased

Note: For information about obtaining an AppId, see Bing Developer Center.

Response

<?xml version="1.0" encoding="utf-8" ?>

<?pageview_candidate?>

<SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.2">

  <Query>

    <SearchTerms>testign</SearchTerms>

  </Query>

  <spl:Spell xmlns:spl="http://schemas.microsoft.com/LiveSearch/2008/04/XML/spell">

    <spl:Total>1</spl:Total>

    <spl:Results>

      <spl:SpellResult>

        <spl:Value>testing </spl:Value>

      </spl:SpellResult>

    </spl:Results>

  </spl:Spell>

  <web:Web xmlns:web="http://schemas.microsoft.com/LiveSearch/2008/04/XML/web">

    <web:Total>5680</web:Total>

    <web:Offset>0</web:Offset>

    <web:Results>

      <web:WebResult>

        <web:Title>Hacker News | PHP Unit testign</web:Title>

        <web:Description>PHP Unit testign: 1 point by amrithk 134 days ago | 1 comment: Interested to know what tools people use/recommend for unit testing for PHP? What do people think about PHPUnit?</web:Description>

        <web:Url>http://news.ycombinator.com/item?id=196435</web:Url>

        <web:DisplayUrl>http://news.ycombinator.com/item?id=196435</web:DisplayUrl>

        <web:DateTime>2008-10-03T15:09:15Z</web:DateTime>

      </web:WebResult>

    </web:Results>

  </web:Web>

</SearchResponse>

AttributeBased Enumeration Example

Request

http://api.bing.net/xml.aspx?AppId = [YOUR_APPID] &Version=2.2&Market=en-US&Query=testign&Sources=web+spell&web.count=1&xmltype=attributebased

Note: For information about obtaining an AppId, see Bing Developer Center.

Response

<?xml version="1.0" encoding="utf-8" ?>

<?pageview_candidate?>

<SearchResponse xmlns="http://schemas.microsoft.com/LiveSearch/2008/04/XML/element" Version="2.2">

  <Query SearchTerms="testign"></Query>

  <spl:Spell xmlns:spl="http://schemas.microsoft.com/LiveSearch/2008/04/XML/spell" Total="1">

    <spl:Results>

      <spl:SpellResult Value="testing "></spl:SpellResult>

    </spl:Results>

  </spl:Spell>

  <web:Web xmlns:web="http://schemas.microsoft.com/LiveSearch/2008/04/XML/web" Total="5680" Offset="0">

    <web:Results>

      <web:WebResult Title="Hacker News | PHP Unit testign" Description="PHP Unit testign: 1 point by amrithk 134 days ago | 1 comment: Interested to know what tools people use/recommend for unit testing for PHP? What do people think about PHPUnit?" Url="http://news.ycombinator.com/item?id=196435" DisplayUrl="http://news.ycombinator.com/item?id=196435" DateTime="2008-10-03T15:09:15Z"></web:WebResult>

    </web:Results>

  </web:Web>

</SearchResponse>