I am working on XML files using DOM parser and I am copying entire data from one xml file into another xml file with changes in values of some nodes.
My XML file looks like below:
<ems:DeterminationRequest>
<ems:MessageInformation>
.........
</ems:MessageInformation>
<ems:case>
<ns17:CalHEERSCaseInfo> ... </ns17:CalHEERSCaseInfo>
<ns17:persons> ..... </ns17:persons>
</ems:case>
</ems:DeterminationRequest>
Now I want to add child node to 'ems:DeterminationRequest' which has other child nodes.
Links reffered for adding new nodes: link1,link2.
I know how to add child node to the parent node using following syntax:
....
Document doc = db.parse(new FileInputStream(new File("in.xml")));
Element element = doc.getDocumentElement();
Node node = doc.createElement("ns17:CaseReferals");
element.appendChild(node);
.....
But I want to add following syntax of node:
<ns17:CaseReferrals >
<ns17:OtherProgramInformationRequest>
<ns17:CHDPInfoInd></ns17:CHDPInfoInd>
<ns17:WICInfoInd></ns17:WICInfoInd>
<ns17:FamilyPACTInfoInd></ns17:FamilyPACTInfoInd>
<ns17:SHOPInfoInd></ns17:SHOPInfoInd>
<ns17:EPSDTInfoInd></ns17:EPSDTInfoInd>
<ns17:VoterRegistrationInfoInd></ns17:VoterRegistrationInfoInd>
<ns17:PCSPInfoInd></ns17:PCSPInfoInd>
</ns17:OtherProgramInformationRequest>
</ns17:CaseReferrals>
So is there any way by which we can create a string of above syntax and ad as a child node to the parent node?