XML has two elements when getting length but null pointer exception when trying to access and append the node




<DG1root>
<DG1>
<DG1.1>1</DG1.1>
<DG1.4>he he he</DG1.4>
<DG1.5>20141128</DG1.5>
<DG1.6>Admitting</DG1.6>
<DG1.15>1</DG1.15>
<DG1.16>
<XCN.1>1</XCN.1>
<XCN.2>Nanayakkara</XCN.2>
<XCN.3>Nanayakkara</XCN.3>
<XCN.4>Doctor of Medicine (M.D.)</XCN.4>
</DG1.16>
<DG1.17>Medication</DG1.17>
</DG1>
<DG1>
<DG1.1>2</DG1.1>
<DG1.4>heeeeeeee</DG1.4>
<DG1.5>20141128</DG1.5>
<DG1.6>Working</DG1.6>
<DG1.15>0</DG1.15>
<DG1.16>
<XCN.1>1</XCN.1>
<XCN.2>Nanayakkara</XCN.2>
<XCN.3>Nanayakkara</XCN.3>
<XCN.4>Doctor of Medicine (M.D.)</XCN.4>
</DG1.16>
<DG1.17>Other</DG1.17>
</DG1>
</DG1root>


after



NodeList listDG1 = symptomAndDiagnosisDoc.getElementsByTagName("DG1root")
.item(0).getChildNodes();

listDG1.getLength()


gives the length of 2. but when i try to append it to a new root, after



Node root = symptomAndDiagnosisDoc.importNode(
patientDoc.getElementsByTagName("ADT_A04").item(0),true);


which symptomAndDiagnsisDoc contains the above xml,



for (int i=0; i<listDG1.getLength(); i++){
root.appendChild(listDG1.item(i));
}


this only append one DG1 element but not the other. I only want to append the DG1 elements.


Please be kind enough to explain what im doing wrong here. Thank you :)


No comments:

Post a Comment