It is necessary to deserialize xml of this type. I wrote such code using the library simple-xml :

@Root public class Valute { @Attribute public String ID; @Element public Integer NumCode; @Element public String CharCode; @Element public Integer Nominal; @Element public String Name; @Element public Double Value; } @Root public class ValCurs { @Attribute public Date Date; @Attribute(name = "name", required = false) public String Name; @ElementList(inline = true, required = false) public List<Valute> Valutes; public Valute get(final String charCode) { for (Valute valute : Valutes) { if (valute.CharCode.equals(charCode)) return valute; } return null; } public static ValCurs parse(String xml) throws Exception { DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); RegistryMatcher m = new RegistryMatcher(); m.bind(Date.class, new DateFormatTransformer(dateFormat)); Reader reader = new StringReader(xml); Persister serializer = new Persister(m); return serializer.read(ValCurs.class, reader, false); } } 

But when deserializing, I get in the Valutes field - null. How to fix it?

  • and XStream did not try? - Senior Pomidor
  • I have not tried. And what with simple-xml will not work? Just started already sort of ... - PECHAPTER
  • I can’t say whether it will come out or not, I would also recommend looking towards Unmarshaller - Senior Pomidor
  • I didn’t quite understand how to use them ... Well, for example, in XStream, an object is sent to fill in, but how to specify which fields are attributes and which are not, also nested lists, as in my example, it’s not clear how to define ... For me, in simple -xml liked the annotations. All through annotations is set. Well, with Unmarshaller there’s something very strange. Neither the object type, nor the object itself is transferred to it, however, it returns some non-typed object ... What's in this object? How does it define the xml structure? - PECHAPTER
  • By the way, I should add that if I use some other library, I need it to work under the android! Because Android application do. - PECHAPTER

0