【发布时间】:2015-03-17 01:50:39
【问题描述】:
我一直在尝试通过获取item 节点的长度来迭代子节点。但是,它显示的是原始长度的两倍。
这是我一直在使用的 XML 代码,
<item>
<title>Title 1</title>
<link>http://www.example.com</link>
<comments>http://www.example.com/#comments</comments>
<pubDate>Mon, 19 Jan 2015 04:05:39 +0000</pubDate>
<dc:creator><![CDATA[Exampple]]></dc:creator>
<category><![CDATA[Hot News]]></category>
<guid isPermaLink="false">http://www.example.com/?p=72278</guid>
<description><![CDATA[<p>Some Description</p>]]></description>
<content:encoded><![CDATA[<p>Some description content.</p>]]></content:encoded>
<wfw:commentRss>http://www.example.com/feed/</wfw:commentRss>
</item>
Java 代码:
NodeList nl = doc.getElementsByTagName("item");
int length = nl.getLength();
Log.d("check", "Item i count = " + length); //shows 10
for (int i = 0; i < length; i++) {
Node currentNode = nl.item(i); // Get the first item
String nodetestName = currentNode.getNodeName();
NodeList nchild = currentNode.getChildNodes(); // Get the child nodes of first item
int clength = nchild.getLength(); // Get the length of child nodes of first item (Shows 21 but original length is 10)
我该怎么办?
【问题讨论】: