Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

NodeList.item(i) returns every other child node

843834Jan 15 2007 — edited Jan 15 2007
I have used the following code to eliminate null elements from a Node.
But somehow NodeList.item(i) only returns every other child node.

The original Node (retNode) is:

<getHearingDetailsByCaseNoWSResponse><hearingDetailsVO xmlns="http://vo.cis.com"><NOA/><applicationNo>sAppNo0</applicationNo><caseNo/><designation/><docID/><duration/><endTime/><hearDate/><judgeName/><natureOfClaim/><outCome/><outComeTime/><outcomeDate/><remarks/><roomNo/><sessionNo/><stEndTime/><tohCode/><typeHear/></hearingDetailsVO></getHearingDetailsByCaseNoWSResponse>

retNode.getLength() gives 19 which is correct.
NodeList lv2List = retNode.getChildNodes();		
int numOfLv2 = lv2List.getLength();
if(numOfLv2 == 0) {
	if(!hasAttribute(node)) parent.removeChild(node);
		return;
	}
		
	for(int i=0; i<numOfLv2; i++) {
		Node lv2Node = lv2List.item(i);
		if(lv2Node == null || lv2Node.getNodeType() != Node.ELEMENT_NODE) continue;
		removeNullElement(lv2Node);	
	}
However, lv2List.item(0) returns <NOA/> element, lv2List.item(0) returns <caseNo/>, lv2List.item(1) returns <docID/>, and lv2List.item(9) returns <typeHear/>. From item(10) to item(18) all returns null.

I was very confused by this.
I am using Xerces-J implementation. I have set
System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");

Did I do something wrong or I missed out something?
Please enlighten me.


Regards,
Xinjun
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 12 2007
Added on Jan 15 2007
3 comments
511 views