在下面的代码中,当我使用getNodeValue()时,我没有得到任何东西,但是当我使用getTextContent()时,它返回我的内容以及它的子内容。任何人都告诉我为什么getNodeValue()不起作用? 这里给出了XML:
http://developer.android.com/training/basics/network-ops/xml.html
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://stackoverflow.com/feeds/tag?tagnames=android&sort=newest");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = httpEntity.getContent();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(is, null);
NodeList rootNode = doc.getElementsByTagName("entry");
for (int i = 0; i < rootNode.getLength(); i++)
{
Node node = rootNode.item(i);
if(node.getNodeType()==Node.ELEMENT_NODE){
Element element = (Element)node;
String title = element.getElementsByTagName("title").item(0).getTextContent();
String author = element.getElementsByTagName("author").item(0).getNodeValue();
String summary = element.getElementsByTagName("summary").item(0).getNodeValue();
String result = title+"\n"+author+"\n"+summary+"";
list.add(result);
}
}