I am developing a program that allows me to print the elements of tags of an XML that I have, this is the instruction that this is my main class, that allows me to print a certain tag:
for(int k=0; k < list3.getLength(); k++) {
Node node3 = list3.item(k);
if(node3.getNodeType() == Node.ELEMENT_NODE) {
Element element3 = (Element) node3;
Concepto concepto3 = new Concepto();
concepto3.setCodigo(element3.getElementsByTagName("Codigo").item(0).getTextContent());
concepto3.setDescripcion(element3.getElementsByTagName("Descripcion").item(0).getTextContent());
concepto3.setUT(element3.getElementsByTagName("UT").item(0).getTextContent());
concepto3.setMonto(element3.getElementsByTagName("Monto").item(0).getTextContent());
ListaConceptos.add(concepto3);
System.out.println(concepto3);
System.out.println(concepto.toString2());
}
}
And this is a piece of the labels that I need to print:
<OperacionesManoObra>
<OperacionManoObra>
<UT>0</UT>
<Monto>0</Monto>
</OperacionManoObra>
<OperacionManoObra>
<UT>0</UT>
<Monto>0</Monto>
</OperacionManoObra>
<OperacionManoObra>
<Codigo>SN</Codigo>
<Descripcion>VEHIC.EN BANCADA:COLOCAR-QUITAR</Descripcion>
<UT>15</UT>
<Monto>337.5</Monto>
</OperacionManoObra>
<OperacionManoObra>
<Codigo>SN</Codigo>
<Descripcion>BANCADA:PREPARAR</Descripcion>
<UT>10</UT>
<Monto>225</Monto>
</OperacionesManoObra>
Where I see the problem lies, is that the first two elements, only have the labels "UT" and "Amount", and the others are normal ... how could I fix it so that in the first two I printed null those who do not have ?, thanks.