【发布时间】:2012-12-13 07:12:25
【问题描述】:
所以,我写了一些小东西来解析 Youtube 用户的提要。
问题是当我调用getNodeValue() 时返回null。为什么是这样?任何想法或替代方法都表示赞赏,谢谢。
这是我目前做事方式的简要说明:
try {
Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse("https://gdata.youtube.com/feeds/api/users/estudiosabiertostv/uploads");
NodeList entries = d.getElementsByTagName("entry");
for(int i = 0; i < entries.getLength(); i++) {
NodeList children = entries.item(i).getChildNodes();
YoutubeVideo video = new YoutubeVideo();
for(int j = 0; j < children.getLength(); j++) {
Node child = children.item(j);
if(child.getNodeName().equals("title")) {
video.title = child.getNodeValue();
break;
}
}
videos.add(video);
}
}
catch (Exception e) {
e.printStackTrace();
}
这是我从中获取 XML 的网址:
https://gdata.youtube.com/feeds/api/users/estudiosabiertostv/uploads
这是一个条目的 sn-p,我正在尝试获取其中的标题
<entry>
<id>http://gdata.youtube.com/feeds/api/videos/oDbOmTY3gDw</id>
<published>2012-12-17T08:14:12.000Z</published>
<category scheme="http://schemas.google.com/g/2005#kind" term="http://gdata.youtube.com/schemas/2007#video"/>
<title type="text">SEAS - Grupo San Valero - Crea tu propia Navidad (2012)</title>
<content type="text">Felicitación de Navidad de SEAS, Estudios Abiertos del Grupo San Valero</content>
<link rel="alternate" type="text/html" href="http://www.youtube.com/watch?v=oDbOmTY3gDw&feature=youtube_gdata"/>
<author>
<name>estudiosabiertostv</name>
<uri>http://gdata.youtube.com/feeds/api/users/estudiosabiertostv</uri>
</author>
</entry>
【问题讨论】:
-
在我的脑海中,标题节点应该有一个子节点 - 一个文本节点,并且应该包含实际的文本。
-
@full.stack.ex 你的东西很棒。创建一个答案,我会接受。