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
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
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
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
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
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)?
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>