Create a new tag in XML
I have the following java file(Customer.java).
public class Customer
{
private String ID;
private FirstName firstName;
private MiddleName middleName;
private LastName lastName;
private String streetno;
private String city;
private String pin;
private String phone;
public FirstName getFirstName() {
return firstName;
}
public void setFirstName(FirstName firstName) {
this.firstName = firstName;
}
public String getID() {
return ID;
}
public void setID(String id) {
ID = id;
}
public LastName getLastName() {
return lastName;
}
public void setLastName(LastName lastName) {
this.lastName = lastName;
}
public MiddleName getMiddleName() {
return middleName;
}
public void setMiddleName(MiddleName middleName) {
this.middleName = middleName;
}
public String getStreetNo() {
return streetno;
}
public void setStreetNo(String streetno) {
this.streetno= streetno;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city= city;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone= phone;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin= pin;
}
Using castor i have created an xml file(customer.xml) which has the following format.
<?xml version="1.0" encoding="UTF-8" ?>
- <customer ID="fbs0001">
<FIRSTNAME>Fred</FIRSTNAME>
<MIDDLENAME>B</MIDDLENAME>
<LASTNAME>Scerbo</LASTNAME>
<STREETNO>19</STREETNO>
<CITY>Bangalore</CITY>
<PIN>560054</PIN>
<PHONE>9886582108</PHONE>
</customer>
I have used a mapping file to get this output.Is there a way where i can get the output xml in the following format without changing the Java object structure.If yes then please suggest how this can be done.
<?xml version="1.0" encoding="UTF-8" ?>
- <customer ID="fbs0001">
<FIRSTNAME>Fred</FIRSTNAME>
<MIDDLENAME>B</MIDDLENAME>
<LASTNAME>Scerbo</LASTNAME>
<ADDRESS>
<STREETNO>19</STREETNO>
<CITY>Bangalore</CITY>
<PIN>560054</PIN>
<PHONE>9886582108</PHONE>
</ADDRESS>
</customer>
That would be invalid XML. You will need a root element. Even if you do have a valid root xml, I am not sure you can easily do it with Castor, if at all. Try doing an additional XLT on the original output xml.