Element root = document.addElement("root");
Element users = root.addElement("users");
for (Iterator<Users> it = uList.iterator();it.hasNext();) {
Users u = it.next();
Element user = users.addElement("user");
user.addElement("user_id").addCDATA(formatString(""+u.getUser_id()));
user.addElement("deleted").addCDATA(formatString(""+u.getDeleted()));
user.addElement("age").addCDATA(formatString(""+CalendarPatterns.getDateByMiliSeconds(u.getAge())));
if (u.getAvailible() != null) {
user.addElement("availible").addCDATA(formatString(""+u.getAvailible().toString()));
} else {
user.addElement("availible").addCDATA("0");
}
user.addElement("deleted").addCDATA(formatString(""+u.getDeleted()));
user.addElement("firstname").addCDATA(formatString(""+u.getFirstname()));
user.addElement("lastname").addCDATA(formatString(""+u.getLastname()));
user.addElement("login").addCDATA(formatString(""+u.getLogin()));
user.addElement("pass").addCDATA(formatString(""+u.getPassword()));
if (u.getActivatehash()!= null) {
user.addElement("activatehash").addCDATA(formatString(""+u.getActivatehash()));
} else {
user.addElement("activatehash").addCDATA(formatString(""));
}
if (u.getExternalUserType() != null) {
user.addElement("externalUserType").addCDATA(formatString(""+u.getExternalUserType()));
} else {
user.addElement("externalUserType").addCDATA(formatString(""));
}
if (u.getExternalUserId() != null) {
user.addElement("externalUserId").addCDATA(formatString(""+u.getExternalUserId()));
} else {
user.addElement("externalUserId").addCDATA(formatString(""));
}
if (u.getResethash() != null) {
user.addElement("resethash").addCDATA(formatString(""+u.getResethash()));
} else {
user.addElement("resethash").addCDATA(formatString(""));
}
if (u.getUserOffers() != null) {
user.addElement("userOffers").addCDATA(formatString(""+u.getUserOffers()));
} else {
user.addElement("userOffers").addCDATA(formatString(""));
}
if (u.getUserSearchs() != null) {
user.addElement("userSearchs").addCDATA(formatString(""+u.getUserSearchs()));
} else {
user.addElement("userSearchs").addCDATA(formatString(""));
}
if (u.getForceTimeZoneCheck() != null) {
user.addElement("forceTimeZoneCheck").addCDATA(formatString(""+u.getForceTimeZoneCheck()));
} else {
user.addElement("ForceTimeZoneCheck").addCDATA(formatString(""));
}
if (u.getLasttrans() != null) {
user.addElement("lasttrans").addCDATA(formatString(""+u.getLasttrans()));
} else {
user.addElement("lasttrans").addCDATA(formatString(""));
}
if (u.getShowContactData() != null) {
user.addElement("showContactData").addCDATA(formatString(""+u.getShowContactData()));
} else {
user.addElement("showContactData").addCDATA(formatString(""));
}
if (u.getShowContactDataToContacts() != null) {
user.addElement("showContactDataToContacts").addCDATA(formatString(""+u.getShowContactDataToContacts()));
} else {
user.addElement("showContactDataToContacts").addCDATA(formatString(""));
}
String pictureuri = u.getPictureuri();
if (pictureuri != null) user.addElement("pictureuri").addCDATA(pictureuri);
else user.addElement("pictureuri").addCDATA(formatString(""));
if ( u.getLanguage_id() != null ) user.addElement("language_id").addCDATA(formatString(u.getLanguage_id().toString()));
else user.addElement("language_id").addCDATA(formatString(""));
if (u.getStatus() != null) {
user.addElement("status").addCDATA(formatString(""+u.getStatus().toString()));
} else {
user.addElement("status").addCDATA("0");
}
user.addElement("regdate").addCDATA(formatString(""+CalendarPatterns.getDateWithTimeByMiliSeconds(u.getRegdate())));
if (u.getTitle_id() != null) {
user.addElement("title_id").addCDATA(formatString(""+u.getTitle_id().toString()));
user.addElement("level_id").addCDATA(formatString(""+u.getLevel_id().toString()));
} else {
user.addElement("title_id").addCDATA("1");
user.addElement("level_id").addCDATA("1");
}
if (u.getOmTimeZone() != null) {
user.addElement("omTimeZone").addCDATA(formatString(""+u.getOmTimeZone().getJname()));
} else {
user.addElement("omTimeZone").addCDATA(formatString(""));
}
if (u.getAdresses() != null) {
user.addElement("additionalname").addCDATA(formatString(""+u.getAdresses().getAdditionalname()));
user.addElement("comment").addCDATA(formatString(""+u.getAdresses().getComment()));
//A User can not have a deleted Adress, you cannot delete the Adress of an User
//String deleted = u.getAdresses().getDeleted()
//Phone Number not done yet
user.addElement("fax").addCDATA(formatString(""+u.getAdresses().getFax()));
if (u.getAdresses().getStates() != null) {
user.addElement("state_id").addCDATA(formatString(""+u.getAdresses().getStates().getState_id().toString()));
} else {
user.addElement("state_id").addCDATA("1");
}
user.addElement("street").addCDATA(formatString(""+u.getAdresses().getStreet()));
user.addElement("town").addCDATA(formatString(""+u.getAdresses().getTown()));
user.addElement("zip").addCDATA(formatString(""+u.getAdresses().getZip()));
// Email and Phone
user.addElement("mail").addCDATA(formatString(""+u.getAdresses().getEmail()));
user.addElement("phone").addCDATA(formatString(""+u.getAdresses().getPhone()));
} else {
user.addElement("additionalname").addCDATA(formatString(""));
user.addElement("comment").addCDATA(formatString(""));
//A User can not have a deleted address, you cannot delete the address of an User without deleting the user
//only SOAP users might have a null
//String deleted = u.getAdresses().getDeleted()
//Phone Number not done yet
user.addElement("fax").addCDATA(formatString(""));
user.addElement("state_id").addCDATA("1");
user.addElement("street").addCDATA(formatString(""));
user.addElement("town").addCDATA(formatString(""));
user.addElement("zip").addCDATA(formatString(""));
user.addElement("mail").addCDATA(formatString(""));
user.addElement("phone").addCDATA(formatString(""));
}
if (u.getUserSipData() != null) {
user.addElement("sip_username").addCDATA(formatString(""+u.getUserSipData().getUsername()));
user.addElement("sip_userpass").addCDATA(formatString(""+u.getUserSipData().getUserpass()));
user.addElement("sip_authid").addCDATA(formatString(""+u.getUserSipData().getAuthId()));
}
Element user_organisations = user.addElement("organisations");
//List<String> organisations = new LinkedList();
for (Iterator<Organisation_Users> iterObj = u.getOrganisation_users().iterator();iterObj.hasNext(); ) {
Element user_organisation = user_organisations.addElement("user_organisation");
Organisation_Users orgUsers = iterObj.next();
if (orgUsers.getOrganisation() != null) {