1

I want to get the XML in atom format of a GoogleDocs spreadsheet using the [generateAtom(..,..)][1] method of the class BaseEntry which a SpreadsheetEntry inherits. But I don't understand the the second parameter in the method, ExtensionProfile. What is it and will this method call suffice if I just want to get the XML in atom format?

XmlWriter x = new XmlWriter();
spreadSheetEntry.generateAtom(x,new ExtensionProfile());

[1]: http://code.google.com/apis/gdata/javadoc/com/google/gdata/data/BaseEntry.html#generateAtom(com.google.gdata.util.common.xml.XmlWriter, com.google.gdata.data.ExtensionProfile)

4

2 回答 2

3

来自ExtensionProfile 的 JavaDoc

配置文件是每种类型的一组允许的扩展以及其他属性。

通常如果你有一个服务,你可以使用Service.getExtensionProfile()来询问它的扩展配置文件。

于 2009-11-25T17:19:23.400 回答
0

详细说明Jon Skeet 的答案,您需要实例化这样的服务:

String developer_key = "mySecretDeveloperKey";
String client_id = "myApplicationsClientId";
YouTubeService service = new YouTubeService(client_id, developer_key);

然后,您可以使用服务的扩展配置文件写入文件:

static void write_video_entry(VideoEntry video_entry) {
    try {
        String cache_file_path = Layout.get_cache_file_path(video_entry);
        File cache_file = new File(cache_file_path);
        Writer writer = new FileWriter(cache_file);
        XmlWriter xml_writer = new XmlWriter(writer);
        ExtensionProfile extension_profile = service.getExtensionProfile();
        video_entry.generateAtom(xml_writer, extension_profile);
        xml_writer.close();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

类似地,您可以使用服务的扩展配置文件读取文件:

static VideoFeed read_video_feed(File cache_file_file) {
    VideoFeed video_feed = new VideoFeed();
    try {
        InputStream input_stream = new FileInputStream(cache_file_file);
        ExtensionProfile extension_profile = service.getExtensionProfile();
        try {
            video_feed.parseAtom(extension_profile, input_stream);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        input_stream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return video_feed;
}
于 2012-12-10T00:48:44.020 回答