How to search an API

I have access to an XML API in the form of the following link as an example, but I want to create a search box (in asp.net) so that users can search for the data with a set of the parameters and return/display the results based on their parameters selected e.g. holiday websites

http://api.tradedoubler.com/1.0/products.xml;q=holidays;limit=10;minPrice=10?token=96CC0E0A10851500F10431D64EC5585BFC8597DF",false);

Can you please advise on an easy method to achieve this?

thanks in advance

Hi

Have you tried any code yet of what you are trying to achieve? Give it a try yourself and ask specific questions here with code snippets and we will be more than willing to help. But at the moment, this question is pretty broad

Cheers

Ok at the moment I can display the data from the API as shown below in the code. This works but it just shows everything in the api URL, which at the moment shows holidays, under 10 as an example. I want to use a search box on a page (page 1) so that the search parameters are passed to the page below (page 2) and return the results based on the search parameters. for example, a user enters the following parameters in the fields of a search box: hotel, paris, under a given price then they submit them to page 2. , so I want to pass the search parameters from page 1 with a search box to the one below (page 2), but not sure how this will fit in as the first page will have a search box in asp.net and the one below is with javascript using Get Method.

Page 2 sample: 
if (window.XMLHttpRequest) {
    //Firefox, Opera, IE7, and other browsers will use the native 
 
    xmlhttp = new XMLHttpRequest();
}
 else
 {
    //IE 5 and 6 will use the ActiveX control
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://api.examplewebsite.com/1.0/products.xml;q=holidays;limit=10;minPrice=10?token=96CC0E0A10851C8597DF",false);
xmlhttp.send();
xmlhttp=xmlhttp.responseXML; 

  document.write("<tr><td>");
  document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
  document.write("</td>");
etc

Any advise / help would be appreciated

Thanks

Ok, Firstly, I would just send the parameters from page 1 to page 2 with GET parameters. Eg. http://www.yourdomain.com/page2/?search=Hotel%20in%20Paris

Then on the second page, if you really want to do it with javascript, you can. But it would probably be best to grab those parameters on page load in .net and do the http request server side. Then just process the results to display it client side

Ok thanks. Doing it purely in .net sounds the best option. The first page is not issue as I can pass the parameters to the second page, but on the second page to get the API data and iterate through the data in the xml, how do I do it in asp.net? I am not keen on using javascript or client side and prefer to use server side, but not sure about the actual syntax of doing in asp.net. Are there any examples or tutorials you can point me to ?
Note the provider only provides me with the following link which is the API in xml

GET","http://api.examplewebsite.com/1.0/products.xml;q=holidays;limit=10;minPrice=10?

Thanks again

Yes, there are plenty of tutorials online when for dealing with xml in asp.net. Google will help you out

Here are a few examples I found doing a quick google search:

or

http://www.codeproject.com/Articles/24375/Working-with-XML

1 Like

Thanks. Just one thing, the example shown and some of the ones i found, only shows how to read or manipulate an xml file that is located on the host server, but I am looking for examples on how to manipulate an xml from a url (API) e.g. http://api

Any ideas and preferably in ASP.net as a few are in C Sharp

Thanks

Hi

I am not sure what you mean. ASP.NET is a framework and C# is a language used to write on the ASP.NET framework. Do you mean you are using VB.NET(which is another language used to write on the ASP.NET framework)?

To load XML from an API, you just need to load it from a WebClient. Do a request and read the response: http://stackoverflow.com/questions/3757731/how-to-read-xml-from-remote-url-in-vb-net

Hi sorry meant vb.net. The example you referenced has errors so not sure if there are other ones that are accurate

Ok found a way to do it and getting there but…I keep getting this error: (name is neither a DataColumn nor a DataRelation for table result.)
not sure why it doesnt display ‘name’ element from the xml file.
Below is both the code and the actual xml content.
Any advise and help would be appreciated

sub Page_Load
if Not Page.IsPostBack then
   dim myproducts=New DataSet
myproducts.ReadXml("http://api.example.com/1.0/products.xml")  
   products.DataSource=myproducts
   products.DataBind()
end if
end sub
</script>
<html>
<body>
<form runat="server">
<asp:Repeater id="products" runat="server">

<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>name</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
  <div>City: <%#Container.DataItem("name")%></div>
</ItemTemplate>

The xml file content from the url:

<result xmlns="urn:com:example:pf:model:xml:output" xmlns:ns2="urn:com:tradedoubler:pf:model:xml:common" version="3.0">
<productHeader>...</productHeader>
<products>
<product language="en">...</product>
<product language="en">
<ns2:name>Pisa Holidays</ns2:name>
<ns2:description>Pisa Holidays</ns2:description>
<ns2:productImage>
http://me.jpg
</ns2:productImage>
<ns2:categories>

EDIT
This post has been reformatted by enclosing the code block in 3 backticks
```
on their own lines.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.