【问题标题】:SAX Parse exception while parsing google calendar解析谷歌日历时出现 SAX 解析异常
【发布时间】:2014-10-15 02:47:33
【问题描述】:

我正在使用 GDATA API 来解析谷歌日历。日历嵌入在网站中:

http://regreformtracker.aba.com/p/dodd-frank-calendar.html

我从上述网站中使用的 iframe src 获得了日历 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

我正在使用下面提到的sn-p:

 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

我不确定是什么错误,请您检查并告诉我哪里出错了?

我尝试使用其他日历(例如我的私人日历)来检查日历 URL 是否有问题,但即便如此我也遇到了同样的问题。

我也尝试使用 CalendarFeed 类而不是 CalendarEventFeed,但我仍然遇到同样的问题。

【问题讨论】:

    标签: java google-calendar-api gdata


    【解决方案1】:

    【讨论】:

    • 感谢您的信息。我想从上述网站中嵌入的日历访问数据。那么如果我上面提到的链接代表一个html页面,我该怎么做呢?我如何知道要用于此日历的正确 URL 是什么?有没有其他方法可以获取上述日历的活动日期和活动信息?
    • 此链接中引用了三个不同的日历:regreform@aba.com、7vccf8rlid30a0v4m1004atiqg@group.calendar.google.com、3rpabc5qjf34l49ho337qh9m04%40group.calendar.google.com 我建议您查看文档事件列表操作:developers.google.com/google-apps/calendar/v3/reference/events/… 但在您这样做之前,请阅读此处的入门指南:developers.google.com/google-apps/calendar/get_started
    猜你喜欢
    • 2011-08-15
    • 2014-09-03
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 2018-08-11
    相关资源
    最近更新 更多