List Info

Thread: ASP.NET and Upcoming API




ASP.NET and Upcoming API
country flaguser name
United States
2007-10-10 11:35:07

I'm currently working on an ASP.NET site that needs to use the
Upcoming API.

I have the following code to get the returned XML:

Dim url As String = "http://upcoming.yahooapis.com/services/rest/?
method=venue.search&;location=Troy,+MI&api_key=<Your Key>&quot;

Dim RequestXMLstring As String = "<?xml version='1.0'?
>;<element1>Some Value</element1>;"
Dim XmlResult As New System.Xml.XmlDocument
Dim anXMLhttpObject As Object
anXMLhttpObject = Server.CreateObject("MSXML2.ServerXMLHTTP")

Try
anXMLhttpObject.open("POST", url, False)
Catch
Response.Write(";Connection cannot be established. Please
try again later.&quot;)
End Try

anXMLhttpObject.setRequestHeader("Content-
Type", "application/x-www-form-urlencoded&quot;)

anXMLhttpObject.setRequestHeader("Content-Length", Len
(RequestXMLstring))

anXMLhttpObject.send(RequestXMLstring)

Dim strResult As String = anXMLhttpObject.responseText

XmlResult.LoadXml(strResult)

'***************************************

Dim bodyAttrib As System.Xml.XmlNodeList =
XmlResult.SelectNodes("rsp/")

For Each attr As XmlNode In bodyAttrib
Dim name As XmlAttribute = DirectCast
(attr.Attributes.GetNamedItem("name"), XmlAttribute)
Dim val As XmlAttribute = DirectCast
(attr.Attributes.GetNamedItem("description&quot;), XmlAttribute)
If name IsNot Nothing AndAlso val IsNot Nothing Then
TextBox1.Text = name.Value & val.Value
End If
Next

I get the results just fine. I'm having a little trouble parsing the
xml here -->XmlResult.SelectNodes(&quot;rsp/&quot;)
I've tried: XmlResult.SelectNodes("rsp/event";)
No luck.. Anyone have any ideas?

Thank you in advance..

__._,_.___
.

__,_._,___
Re: ASP.NET and Upcoming API
country flaguser name
United States
2007-10-10 11:42:05

Also, it looks like you're using a POST request to do a GET query. That
may be returning an error instead of event objects, so that could be
getting in your way. Take a look at the actual URL and try pasting it in
a browser. Also, you can try printing out the returned XML as plaintext
to help in your debugging, to make sure the problem isn't before your
query call. If you're using XPath (not sure, i'm not a .Net guy), you
may want to try /rsp/event. The advantage of building a REST-like API is
that we usually print out helpful error messages on the way.

stewsterl wrote:
&gt;
>
> I'm currently working on an ASP.NET site that needs to use the
> Upcoming API.
>;
> I have the following code to get the returned XML:
>;
> Dim url As String = "http://upcoming.yahooapis.com/services/rest/?
> <http://upcoming.yahooapis.com/services/rest/?>
> method=venue.search&amp;location=Troy,3;MI&api_key=<Your Key>&quot;
>
> Dim RequestXMLstring As String = "<?xml version='1.0'?
>; ><element1>Some Value</element1>;"
> Dim XmlResult As New System.Xml.XmlDocument
> Dim anXMLhttpObject As Object
&gt; anXMLhttpObject = Server.CreateObject("MSXML2.ServerXMLHTTP")
>
> Try
> anXMLhttpObject.open("POST", url, False)
&gt; Catch
&gt; Response.Write(";Connection cannot be established. Please
&gt; try again later.&quot;)
> End Try
>
> anXMLhttpObject.setRequestHeader("Content-
&gt; Type", "application/x-www-form-urlencoded&quot;)
&gt;
> anXMLhttpObject.setRequestHeader("Content-Length", Len
> (RequestXMLstring))
>
> anXMLhttpObject.send(RequestXMLstring)
>
> Dim strResult As String = anXMLhttpObject.responseText
>
> XmlResult.LoadXml(strResult)
>
> '***************************************
>
> Dim bodyAttrib As System.Xml.XmlNodeList =
> XmlResult.SelectNodes("rsp/")
>
> For Each attr As XmlNode In bodyAttrib
> Dim name As XmlAttribute = DirectCast
> (attr.Attributes.GetNamedItem("name&quot;), XmlAttribute)
> Dim val As XmlAttribute = DirectCast
> (attr.Attributes.GetNamedItem("description";), XmlAttribute)
> If name IsNot Nothing AndAlso val IsNot Nothing Then
>; TextBox1.Text = name.Value & val.Value
> End If
> Next
>;
> I get the results just fine. I'm having a little trouble parsing the
> xml here -->XmlResult.SelectNodes(&quot;rsp/&quot;)
> I've tried: XmlResult.SelectNodes("rsp/event";)
> No luck.. Anyone have any ideas?
&gt;
> Thank you in advance..
>
>

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )