这段 Java 代码打印了来自 NYT 世界 RSS 的每个项目的标题、链接和发布日期。但对于 NYT 的 Science RSS,它不会打印链接字段。这里发生了什么?
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse( direccion );
XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("/rss/channel/item");
NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
Node nodoTitulo = (Node) xpath.evaluate("title", node, XPathConstants.NODE);
System.out.println(nodoTitulo.getTextContent());
Node nodoLink = (Node) xpath.evaluate("link", node, XPathConstants.NODE);
System.out.println(nodoLink.getTextContent());
Node nodoFecha = (Node) xpath.evaluate("pubDate", node, XPathConstants.NODE);
System.out.println(nodoFecha.getTextContent());
System.out.println();
}