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