阅读来自Google日历服务与Java的XML响应
问题描述:
我想使用作为Google日历API一部分提供的新查询繁忙时间API检索用户的繁忙时间。结果是一个包含忙次用户的块只读饲料,看起来像下面这样:阅读来自Google日历服务与Java的XML响应
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gCal="http://schemas.google.com/gCal/2005"
xmlns:gd="http://schemas.google.com/g/2005"
gd:kind='calendar#freebusy' >
<id>http://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com</id>
<updated>2010-03-13T00:00:00.000Z</udpated>
<link rel='self'
href='https://www.google.com/calendar/feeds/default/freebusy/busy-times/liz%40example.com' />
<author>
<name>[email protected]</name>
<email>[email protected]</email>
</author>
<gCal:timeRange>
<gd:when startTime='2010-03-13T00:00:00Z' endTime='2010-03-14T00:00:00Z'/>
<gCal:timeRange>
<gCal:busy>
<gd:when startTime='2010-03-13T14:00Z' endTime='2010-03-13T14:30Z'/>
</gCal:busy>
<gCal:busy>
<gd:when startTime='2010-03-13T16:00Z' endTime='2010-03-13T16:30Z'/>
</gCal:busy>
</entry>
基于上述回输,我该如何使用日历数据API for Java来获得的每块忙碌的时间,以便我可以阅读和做他们喜欢打印到终端的东西?这个返回的Feed的类型是什么,CalendarEventFeed,CalendarFeed,...?
CalendarService service = new CalendarService("myapp-v1");
service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
URL feedUrl = new URL(METAFEED_URL_BASE+FREEBUSY_FEED_URL_SUFFIX+user.username());
CalendarEventFeed resultFeed = service.getFeed(feedUrl, CalendarEventFeed.class);
答
AppEngine支持(自1.2.8开始)JAXB XML到对象的数据绑定API。 Web上有很多示例和教程(尽管大多数注重于从XML模式生成自动类 - 您不需要这样做)。示例:http://www.vogella.de/articles/JAXB/article.html
或者,您可以使用Calendar Data API for Java,并完全放弃XML转换步骤。
谢谢,你的回答非常有帮助,但我意识到我提出了错误的问题。我已编辑并重新命名我的帖子。非常感谢你让我朝着正确的方向思考。 – mcorley 2011-05-03 03:35:46