0

I'm using Java to create an xml document.

I want to have the following:

 <epsos:asContent classCode="CONT">
    <epsos:containerPackagedMedicine classCode="CONT" determinerCode="INSTANCE">
       <epsos:name>KLARICID OD CON.R.TAB 500MG/TAB BTx6(BLIST1x6)</epsos:name>
       <epsos:formCode nullFlavor="NI"/>
       <epsos:capacityQuantity unit="1" value="6"/>
       <epsos:capTypeCode nullFlavor="NA"/>
    </epsos:containerPackagedMedicine>
 </epsos:asContent>

I want to create the above code using dom.

My current code is the one below, but epsos:containerPackagedMedicine is not a sub element. Do you know how to fix this?

NodeList nodes = dom.getElementsByTagName("manufacturedMaterial");
for (int i = 0; i < nodes.getLength(); i++) {
   Node node = nodes.item(i);
   Element asContentEl = dom.createElement("epsos:asContent");
   asContentEl.setAttribute("code", "CONT");
   asContentEl.setNodeValue("epsos:containerPackagedMedicine");
   node.appendChild(asContentEl);
}

Using the above code I only get:

 <manufacturedMaterial classCode="MMAT" determinerCode="KIND">                                
 <epsos:asContent code="CONT"/></manufacturedMaterial>
zinon
  • 4,427
  • 14
  • 70
  • 112
  • I don't see `"code", "ACTI"` in your desired output.Where do you get `manufacturedMaterial`? – CrazySabbath Oct 09 '18 at 11:34
  • @CrazySabbath Yes, you are right. I will correct my question right now. `manufacturedMaterial` is an element that is already in the `xml`. I want to add elements with sub elements in this. – zinon Oct 09 '18 at 11:36

0 Answers0