Я пытаюсь выполнить итерацию дочерних узлов, получив длину узла 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)
Что я должен делать?
возможно дубликат [Java Dom парсер сообщает неправильное количество дочерних узлов] (http://stackoverflow.com/questions/11649396/java-dom-parser-reports-wrong-number-of-child-nodes) – Louis