Я пытаюсь сериализовать объект android.location.Address, используя Simple 2.7.1.Как вы сериализуете объект android.location.address с помощью платформы SimpleXML 2.7?
Я попытался создать конвертер ...
public class AddressConverter implements Converter<Address> {
@Override
public Address read(InputNode node) throws Exception {
...
//Not included because this part works!!!!
}
@Override
public void write(OutputNode node, Address addr) throws Exception {
node.setAttribute("Locale", addr.getLocale().toString().replace("_", "-"));
OutputNode child = null;
if (addr.getMaxAddressLineIndex() > 0) {
for (int index = 0; index <= addr.getMaxAddressLineIndex(); index++) {
child = node.getChild("AddressLine");
child.setAttribute("Index", String.valueOf(index));
child.setValue(addr.getAddressLine(index));
}
}
if (addr.getFeatureName() != null && addr.getFeatureName().length() > 0) {
child = node.getChild("FeatureName");
child.setValue(addr.getFeatureName());
child.commit();
}
if (addr.getPremises() != null && addr.getPremises().length() > 0) {
child = node.getChild("Premises");
child.setValue(addr.getPremises());
child.commit();
}
if (addr.getSubThoroughfare() != null && addr.getSubThoroughfare().length() > 0) {
child = node.getChild("SubThoroughfare");
child.setValue(addr.getSubThoroughfare());
child.commit();
}
if (addr.getThoroughfare() != null && addr.getThoroughfare().length() > 0) {
child = node.getChild("Thoroughfare");
child.setValue(addr.getThoroughfare());
child.commit();
}
if (addr.getSubLocality() != null && addr.getSubLocality().length() > 0) {
child = node.getChild("SubLocality");
child.setValue(addr.getSubLocality());
child.commit();
}
if (addr.getLocality() != null && addr.getLocality().length() > 0) {
child = node.getChild("Locality");
child.setValue(addr.getLocality());
child.commit();
}
if (addr.getSubAdminArea() != null && addr.getSubAdminArea().length() > 0) {
child = node.getChild("SubAdminArea");
child.setValue(addr.getSubAdminArea());
child.commit();
}
if (addr.getAdminArea() != null && addr.getAdminArea().length() > 0) {
child = node.getChild("AdminArea");
child.setValue(addr.getAdminArea());
child.commit();
}
if (addr.getPostalCode() != null && addr.getPostalCode().length() > 0) {
child = node.getChild("PostalCode");
child.setValue(addr.getPostalCode());
child.commit();
}
if (addr.getCountryCode() != null && addr.getCountryCode().length() > 0) {
child = node.getChild("CountryCode");
child.setValue(addr.getCountryCode());
child.commit();
}
if (addr.getCountryName() != null && addr.getCountryName().length() > 0) {
child = node.getChild("CountryName");
child.setValue(addr.getCountryName());
child.commit();
}
if (addr.getLatitude() != 0) {
child = node.getChild("Latitude");
child.setValue(String.valueOf(addr.getLatitude()));
child.commit();
}
if (addr.getLongitude() != 0) {
child = node.getChild("Longitude");
child.setValue(String.valueOf(addr.getLongitude()));
child.commit();
}
if (addr.getPhone() != null && addr.getPhone().length() > 0) {
child = node.getChild("Phone");
child.setValue(addr.getPhone());
child.commit();
}
node.commit();
}
@SuppressLint("DefaultLocale")
private Locale getLocale(String strLocale) {
String[] splits = strLocale.split("-", 3);
switch (splits.length) {
case 3:
return new Locale(splits[0].toLowerCase(), splits[1].toUpperCase(), splits[2].toUpperCase());
case 2:
return new Locale(splits[0].toLowerCase(), splits[1].toUpperCase());
default:
return new Locale(splits[0].toLowerCase());
}
}
}
Я не могу получить write
писать дочерние элементы.
Может кто-нибудь, пожалуйста, помогите мне ?!
Любые предложения о том, как создавать дочерние узлы с OutputNode, также будут очень благодарны, поскольку вы можете видеть, что я пробовал документацию, но я не могу понять это!