gpt4 book ai didi

java - imdb 仅获取电影摘要 java (xml)

转载 作者:行者123 更新时间:2023-12-01 11:37:28 25 4
gpt4 key购买 nike

是否有一些简单的方法可以在 Java 程序中将 imdb 电影的摘要作为字符串值获取。我有一个包含 imdb-id 的程序,我希望在我的应用程序中显示该电影的故事情节。

我不知道 IMDB 是否有某种简单的方法来做到这一点。因为我在使用 xml 时遇到了一些麻烦。

http://www.omdbapi.com/?i=tt2820852&plot=full&r=xml

最佳答案

我更喜欢 JAXB,这就是使用 JAXB 的方式:

public static void main(String[] args) throws Exception {
InputStream stream = new FileInputStream("imdb.xml"); // use your stream source
JAXBContext ctx = JAXBContext.newInstance(Root.class);
Unmarshaller um = ctx.createUnmarshaller();
JAXBElement<Root> imdb = um.unmarshal(new StreamSource(stream), Root.class);
System.out.println(imdb.getValue().movie.plot);
}

public class Root {
@XmlElement(name="movie")
public Movie movie;
}

public class Movie {
@XmlAttribute(name="plot")
public String plot;
// Add fields for other attributes you want to read
}

关于java - imdb 仅获取电影摘要 java (xml),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29822286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com