我使用GDATA API解析谷歌日历。日历嵌入在网站中:
http://regreformtracker.aba.com/p/dodd-frank-calendar.html
我从上面提到的网站中使用的iframe src获得了日历网址:
https://www.google.com/calendar/b/0/embed?showTitle=0&height=600&wkst=1&bgcolor=%23FFFFFF&src=regreform%40aba.com&color=%23182C57&src=7vccf8rlid30a0v4m1004atiqg%40group.calendar.google.com&color=%23125A12&src=3rpabc5qjf34l49ho337qh9m04%40group.calendar.google.com&color=%23691426&ctz=America%2FNew_York
我正在使用下面提到的代码段:
URL feedURL = new URL("https://www.google.com/calendar/b/0/embed?showTitle=0&height=600&wkst=1&bgcolor=%23FFFFFF&src=regreform%40aba.com&color=%23182C57&src=7vccf8rlid30a0v4m1004atiqg%40group.calendar.google.com&color=%23125A12&src=3rpabc5qjf34l49ho337qh9m04%40group.calendar.google.com&color=%23691426&ctz=America%2FNew_York");
CalendarService service = new CalendarService("TestCalendarFeed");
CalendarEventFeed resultFeed = service.getFeed(feedURL , CalendarEventFeed.class);
我得到SAXParseException,下面是相同的堆栈跟踪:
[Fatal Error] strict.dtd:81:5: The declaration for the entity "ContentType" must end with '>'.
Oct 13, 2014 2:09:22 PM com.google.gdata.util.LogUtils logException
WARNING: org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.01//EN; systemId: http://www.w3.org/TR/html4/strict.dtd; lineNumber: 81; columnNumber: 5; The declaration for the entity "ContentType" must end with '>'.
Message: The declaration for the entity "ContentType" must end with '>'.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1236)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at org.xml.sax.helpers.ParserAdapter.parse(ParserAdapter.java:430)
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.data.BaseFeed.parseAtom(Unknown Source)
at com.google.gdata.data.BaseFeed.readFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at com.google.gdata.client.GoogleService.getFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at sample.calendar.TestCalendarFeed.printAllEvents(TestCalendarFeed.java:116)
at sample.calendar.TestCalendarFeed.main(TestCalendarFeed.java:472)
The server had a problem handling your request.
com.google.gdata.util.ParseException: org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.01//EN; systemId: http://www.w3.org/TR/html4/strict.dtd; lineNumber: 81; columnNumber: 5; The declaration for the entity "ContentType" must end with '>'.
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.util.XmlParser.parse(Unknown Source)
at com.google.gdata.data.BaseFeed.parseAtom(Unknown Source)
at com.google.gdata.data.BaseFeed.readFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at com.google.gdata.client.GoogleService.getFeed(Unknown Source)
at com.google.gdata.client.Service.getFeed(Unknown Source)
at sample.calendar.TestCalendarFeed.printAllEvents(TestCalendarFeed.java:116)
at sample.calendar.TestCalendarFeed.main(TestCalendarFeed.java:472)
Caused by: org.xml.sax.SAXParseExceptionpublicId: -//W3C//DTD HTML 4.01//EN; systemId: http://www.w3.org/TR/html4/strict.dtd; lineNumber: 81; columnNumber: 5; The declaration for the entity "ContentType" must end with '>'.
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1236)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:568)
at org.xml.sax.helpers.ParserAdapter.parse(ParserAdapter.java:430)
... 9 more
我不确定错误是什么,请您检查并告诉我哪里出错了?
我尝试使用其他日历,比如我的私人日历来检查日历网址是否存在问题,但即便如此,我也遇到同样的问题。
我也尝试使用CalendarFeed类而不是CalendarEventFeed,但我仍然遇到同样的问题。
答案 0 :(得分:1)
您的Feed网址未指向GData内容。 https://www.google.com/calendar/b/0/embed?showTitle=0&height=600&wkst=1&bgcolor=%23FFFFFF&src=regreform%40aba.com&color=%23182C57&src=7vccf8rlid30a0v4m1004atiqg%40group.calendar.google.com&color=%23125A12&src=3rpabc5qjf34l49ho337qh9m04%40group.calendar.google.com&color=%23691426&ctz=America%2FNew_York是一个html网页,而不是xml Feed。在任何情况下,GData都已弃用,不应使用(将于今年11月关闭)。尝试通过API v3(https://developers.google.com/google-apps/calendar)来阅读此日历。