If my xml has two nodes with the same name, how to know the node I'm into?

Viewed 23

I have the following xml file that contains twice the element manufacturedMaterial.

I'm using NodeList nodes = dom.getElementsByTagName("manufacturedMaterial"); to access the elements of manufacturedMaterial and add some subelements. However, the subelements are added also to the second manufacturedMaterial.

The code I'm using is:

for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
}

Is there a way to check if I'm in the first or second node of manufacturedMaterial?

<product>
    <manufacturedProduct classCode="MANU">
        <templateId root="1.3.6.1.4.1.12559.11.10.1.3.1.3.1"/>
        <templateId root="2.16.840.1.113883.10.20.1.53"/>
        <manufacturedMaterial classCode="MMAT" determinerCode="KIND">
            <code code="10219000" codeSystem="0.4.0.127.0.16.1.1.2.1" codeSystemName="EDQM" codeSystemVersion="2022-01-18" displayName="Tablet"/>
            <name>ALGOFEN TABLET 500MG</name>
            <epsos:desc xmlns="">500 mg</epsos:desc>
            <epsos:formCode xmlns="" code="658244" codeSystem="2.16.724.4.21.5.15.4" displayName="PARACETAMOL NORMON 500MG 20 COMPRIMIDOS EFG"/>
            <epsos:asContent xmlns="urn:epsos-org:ep:medication" classCode="CONT">
                <epsos:containerPackagedMedicine xmlns="" classCode="CONT" determinerCode="INSTANCE">
                    <epsos:name/>
                    <epsos:formCode code="116" codeSystem="1.3.6.1.4.1.12559.11.10.1.3.1.44.4" codeSystemName="eHDSIDisplayLabel" displayName=""/>
                    <epsos:capacityQuantity unit="1" value="20.0"/>
                    <epsos:capTypeCode nullFlavor="NA"/>
                </epsos:containerPackagedMedicine>
            </epsos:asContent>
            <epsos:asSpecializedKind xmlns="urn:epsos-org:ep:medication" classCode="GEN">
                <epsos:generalizedMedicineClass classCode="MMAT">
                    <code code="N02BE01" codeSystem="2.16.840.1.113883.6.73" codeSystemName="Anatomical Therapeutic Chemical" codeSystemVersion="2022-01" displayName="paracetamol"/>
                </epsos:generalizedMedicineClass>
            </epsos:asSpecializedKind>
        </manufacturedMaterial>
    </manufacturedProduct>
</product>
<entryRelationship typeCode="REFR">
    <sequenceNumber value="1"/>
    <substanceAdministration classCode="SBADM" moodCode="INT">
        <id extension="JE000233461" root="2.16.724.4.9.30.40"/>
        <text>
            <reference value="#medicine.1"/>
        </text>
        <statusCode code="completed"/>
        <effectiveTime nullFlavor="UNK" xsi:type="IVL_TS"/>
        <doseQuantity nullFlavor="UNK"/>
        <consumable typeCode="CSM">
            <manufacturedProduct classCode="MANU">
                <templateId root="1.3.6.1.4.1.12559.11.10.1.3.1.3.1"/>
                <templateId root="2.16.840.1.113883.10.20.1.53"/>
                <manufacturedMaterial classCode="MMAT" determinerCode="KIND">
                    <code code="10219000" codeSystem="0.4.0.127.0.16.1.1.2.1" codeSystemName="EDQM" codeSystemVersion="2022-01-18" displayName="Tablet"/>
                    <name>PARACETAMOL NORMON 500 mg COMPRIMIDOS EFGPARACETAMOL NORMON 500 mg COMPRIMIDOS EFG</name>
                    <epsos:formCode xmlns=""/>
                    <epsos:asContent xmlns="urn:epsos-org:ep:medication" classCode="CONT">
                        <epsos:containerPackagedMedicine xmlns="" classCode="CONT" determinerCode="INSTANCE">
                            <epsos:name/>
                            <epsos:formCode/>
                            <epsos:capacityQuantity/>
                            <epsos:capTypeCode nullFlavor="NA"/>
                        </epsos:containerPackagedMedicine>
                    </epsos:asContent>
                    <epsos:asSpecializedKind xmlns="urn:epsos-org:ep:medication" classCode="GEN">
                        <epsos:generalizedMedicineClass classCode="MMAT">
                            <code code="N02BE01" codeSystem="2.16.840.1.113883.6.73" codeSystemName="Anatomical Therapeutic Chemical" codeSystemVersion="2022-01" displayName="paracetamol"/>
                        </epsos:generalizedMedicineClass>
                    </epsos:asSpecializedKind>
                </manufacturedMaterial>
            </manufacturedProduct>
        </consumable>
    </substanceAdministration>
</entryRelationship>
0 Answers
Related