List Info

Thread: Re: ASP.NET and Upcoming API




Re: ASP.NET and Upcoming API
user name
2007-10-10 12:04:57

Wow! Thanks for the quick reply.
I did change my POST request to a GET.
My issue is in parsing the xml. I get a valid xml response.
XmlResult.LoadXml(strResult)
I get the same valid response as if I entered it in a web browser.
So my issue is parsing that results. Mainly Here-->

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

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"), XmlAttribute)
If name IsNot Nothing AndAlso val IsNot Nothing Then
TextBox1.Text = name.Value & val.Value
End If
Next

--- In yws-events%40yahoogroups.com">yws-eventsyahoogroups.com, Gordon Luk <gluk...> wrote:
&gt;
> 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
&gt; > 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..
> >
> >
>;

__._,_.___
Recent Activity
Visit Your Group
Find Enlightenment

Yoga groups and

resources on

Yahoo! Groups.

Re: Re: ASP.NET and Upcoming API
user name
2007-10-10 12:23:36

Hmm, anyone on the list a .NET person?

stewsterl wrote:
&gt;
>
> Wow! Thanks for the quick reply.
&gt; I did change my POST request to a GET.
>; My issue is in parsing the xml. I get a valid xml response.
> XmlResult.LoadXml(strResult)
> I get the same valid response as if I entered it in a web browser.
> So my issue is parsing that results. Mainly Here-->
>
> Dim bodyAttrib As System.Xml.XmlNodeList = XmlResult.SelectNodes
> ("/rsp/event&quot;)
>
> 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
>;
> --- In yws-events%40yahoogroups.com">yws-eventsyahoogroups.com <mailto:yws-events%40yahoogroups.com&gt;,
> Gordon Luk <gluk...> wrote:
&gt; >
>; > Also, it looks like you're using a POST request to do a GET query.
&gt; That
>; > may be returning an error instead of event objects, so that could
&gt; 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
&gt; your
>; > query call. If you're using XPath (not sure, i'm not a .Net guy),
&gt; 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
&gt; = "http://upcoming.yahooapis.com/services/rest/?
> <http://upcoming.yahooapis.com/services/rest/?>
> > > <http://upcoming.yahooapis.com/services/rest/?
> <http://upcoming.yahooapis.com/services/rest/?>&gt;
> > > 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..
> > >
>; > >
>; >
>;
>

__._,_.___
.

__,_._,___
Re: ASP.NET and Upcoming API
user name
2007-10-10 13:20:41

--- In yws-events%40yahoogroups.com">yws-eventsyahoogroups.com, "stewsterl" <stewsterl...> wrote:
&gt;
> Wow! Thanks for the quick reply.
> I did change my POST request to a GET.
> My issue is in parsing the xml. I get a valid xml response.
> XmlResult.LoadXml(strResult)
> I get the same valid response as if I entered it in a web browser.
> So my issue is parsing that results. Mainly Here-->
>
> Dim bodyAttrib As System.Xml.XmlNodeList = XmlResult.SelectNodes
> ("/rsp/event&quot;)

SelectNodes is an XPath query, simply do "//event" (on *DocumentElement*).

Dim events As System.Xml.XmlNodeList =
XmlResult.DocumentElement.SelectNodes("//event")

>
>
> For Each attr As XmlNode In bodyAttrib

For Each event As XmlNode In events

Dim name as string = event.Attributes.GetNamedItem("name&quot;).Value;
Dim description as string =
event.Attributes.GetNamedItem("description&quot;).Value;

This should work from my point of view, did you test for an error ?
(It's always good to test your URL in a browser directly (or curl,
forget that you're obviously on Windows).

I know pretty nothing in VB.NET (except RTFM).

Best of luck,

> 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
>;
> --- In yws-events%40yahoogroups.com">yws-eventsyahoogroups.com, Gordon Luk <gluk> wrote:
&gt; >
>; > 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-3]

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