Accessing the length of child nodes returns twice the original count



I've been trying to iterate the child nodes by getting the length of a item node. But, it shows double the size of the original length.


This is the XML code i've been using,



<item>
<title>Title 1</title>
<link>http://ift.tt/1IW9t0J;
<comments>http://ift.tt/1GhdFuj;
<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://ift.tt/1IW9qlM;
<description><![CDATA[<p>Some Description</p>]]></description>
<content:encoded><![CDATA[<p>Some description content.</p>]]></content:encoded>
<wfw:commentRss>http://ift.tt/1GhdGy8;
</item>


Java Code :



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)


What should i do?


No comments:

Post a Comment