I am having problems creating an xml doc with the hierarchy I am looking for ..
<claimants>
<claimant>
<Area>Discrimination/Equality</Area>
<Complaints>1</Complaints>
<AssocatedComplaints>3</AssocatedComplaints>
</claimant>
<claimant>
<Area>Redundancy</Area>
<Complaints>1</Complaints>
<AssocatedComplaints>3</AssocatedComplaints>
</claimant>
I am getting this -
<claimants>
<claimant>
<Area>Discrimination/Equality</Area>
<Complaints>1</Complaints>
<AssocatedComplaints>3</AssocatedComplaints>
<Area>Redundancy</Area>
<Complaints>1</Complaints>
<AssocatedComplaints>3</AssocatedComplaints>
<Area>Terms and Conditions of Employment</Area>
<Complaints>1</Complaints>
<AssocatedComplaints>3</AssocatedComplaints>
</claimant>
Here is the relevant part of the code, appendchild does not work as I would have expected, I have tried a couple of other options, how can I get the claimant element to populate and repeat ??
Document document = new DocumentImpl();
Element claimants = document.createElement("claimants");
Element claimant = document.createElement("claimant");
... ...
rs = ps.executeQuery();
while (rs.next()) {
// get data in
String area = rs.getString("Area");
System.out.println(">> Area : "+area);
complaints = rs.getString("Complaints");
System.out.println(">> Complaints : "+ complaints);
associated = rs.getString("Associated");
System.out.println(">> Associated : "+associated);
// write text elements
Element eArea = document.createElement("Area");
eArea.appendChild(document.createTextNode(area));
Element eComplaints = document.createElement("Complaints");
eComplaints.appendChild(document.createTextNode(complaints));
Element eAssociated = document.createElement("AssocatedComplaints");
eAssociated.appendChild(document.createTextNode(associated));
// append to claimant
System.out.println("appending ELEMENTS to claimant");
claimant.appendChild(eArea);
claimant.appendChild(eComplaints);
claimant.appendChild(eAssociated);
// append to claimants
System.out.println("appending claimant to claimants");
claimants.appendChild(claimant);
//claimants.insertBefore(claimant, claimants.firstChild);
System.out.println("creating new element claimant");
Element claimant = document.createElement("claimant");
}
document.appendChild(claimants);
thanks for any help ..