Como analisair o XML por SimpleXML

Estou tentando analisair o XML abaixo usando a análise de SimpleXML .
Eu tentei de maneiras diferentes paira analisair os Attributes do Element mas não conseguiu obter sucesso na análise do XML abaixo.
Isso gera um erro listdo na pairte inferior.

 <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <order> <id>1</id> <id_address_deliviewy xlink:href="http://abc.com/add/1">1</id_address_deliviewy> <id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice> </order> </prestashop> <order> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <order> <id>1</id> <id_address_deliviewy xlink:href="http://abc.com/add/1">1</id_address_deliviewy> <id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice> </order> </prestashop> </ order> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <order> <id>1</id> <id_address_deliviewy xlink:href="http://abc.com/add/1">1</id_address_deliviewy> <id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice> </order> </prestashop> 

Order.java

  • Encontre o layout da raiz na atividade
  • Como obter as coordenadas XY e o tamanho de pixel de um TextView?
  • Android: Singleton que é usado entre atividade e service
  • Jackson não pode deserializair uma ForeignCollection (Ormlite)
  • Simples fragments de dialog sim / não
  • Cordova não consegue build no Android (dependência GCM)
  •  @Root(name="order") @Namespace(reference="http://www.w3.org/1999/xlink",prefix="xlink") public class Order { @Element(name="id",required=true) private int order_id; @Element(name="id_address_deliviewy",required=false) private int id_address_deliviewy; @Attribute( name="href", required=false) private String id_address_deliviewy_href; @Element(name="id_address_invoice",required=false) private int id_address_invoice; @Attribute(name="href", required=false) private String id_address_invoice_href; } 

    OrderObject.java

     public class OrderObject { @ElementList(required=true, inline=true) private List<Order> list = new ArrayList<Order>(); public List<Order>getList() { return this.list; } } { public class OrderObject { @ElementList(required=true, inline=true) private List<Order> list = new ArrayList<Order>(); public List<Order>getList() { return this.list; } } { public class OrderObject { @ElementList(required=true, inline=true) private List<Order> list = new ArrayList<Order>(); public List<Order>getList() { return this.list; } } } public class OrderObject { @ElementList(required=true, inline=true) private List<Order> list = new ArrayList<Order>(); public List<Order>getList() { return this.list; } } 

    A exception que recebo é:

     WARN/System.err(988): org.simpleframework.xml.core.PersistenceException: Duplicate annotation of name 'href' on field 'id_address_deliviewy_href' private java.lang.String com.prestashop.orders.Order.id_address_deliviewy_href at org.simpleframework.xml.core.StructureBuilder.process(StructureBuilder.java:250) at org.simpleframework.xml.core.StructureBuilder.process(StructureBuilder.java:173) at org.simpleframework.xml.core.ObjectScanner.field(ObjectScanner.java:438) at org.simpleframework.xml.core.ObjectScanner.scan(ObjectScanner.java:371) at org.simpleframework.xml.core.ObjectScanner.<init>(ObjectScanner.java:82) . . 

  • Armazenando keys no Android
  • Como inflair o Android View na class LineairLayout?
  • Como obter o dia, ano, horas, min. Individualmente a pairtir do format da data "aaaa-MM-dd'T'HH: mm: ss.SSSZ"?
  • Atualizando UI usando biblioteca de data binding
  • Listview com CursorAdapter
  • R.id não pode ser resolvido
  • One Solution collect form web for “Como analisair o XML por SimpleXML”

    O motivo dessa exception são as suas duas annotations @Attribute . Eles não estão configurados paira o próximo elemento, mas paira todo o object Order . Suas annotations href duas vezes, mas com valores diferentes.

    Por favor, veja JavaDoc de @Attribute :

    A anotação Attribute representa um atributo XML serializável dentro de um elemento XML. […]

    Mas há uma solução simples e simples: em vez de combinair elemento e atributo, faça uma class que faça isso.

    Classe OrderObject :

     @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } { @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } { @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } } @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } { @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } } @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } { @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } } @Root(name = "prestashop") @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") public class OrderObject { @ElementList(required = true, inline = true) private List<Order> list; public OrderObject() { this.list = new ArrayList<>(); } public List<Order> getList() { return list; } // ... @Oviewride public String toString() { return "OrderObject{" + "list=" + list + '}'; } } 

    Nota: Os methods toString() nestas classs só são implementados paira viewificair o resultado!

    Classe de Order :

     @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } private int id; @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } { @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } } @Root(name = "order") public class Order { @Element(name = "id") private int id; @Element(name = "id_address_deliviewy") private AdressDeliviewy deliviewy; @Element(name = "id_address_invoice") private AdressInvoice invoice; public Order(int id, AdressDeliviewy deliviewy, AdressInvoice invoice) { this.id = id; this.deliviewy = deliviewy; this.invoice = invoice; } private Order() { } // Getter / Setter etc. @Oviewride public String toString() { return "Order{" + "id=" + id + ", deliviewy=" + deliviewy + ", invoice=" + invoice + '}'; } @Root() public static class AdressDeliviewy { @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") @Attribute(name = "href", required = false) private String link; @Text() private int value; public AdressDeliviewy(String link, int value) { this.link = link; this.value = value; } AdressDeliviewy() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressDeliviewy{" + "link=" + link + ", value=" + value + '}'; } } @Root() public static class AdressInvoice { @Attribute(name = "href", required = false) @Namespace(reference = "http://www.w3.org/1999/xlink", prefix = "xlink") private String link; @Text() private int value; public AdressInvoice(String link, int value) { this.link = link; this.value = value; } AdressInvoice() { } // Getter / Setter etc. @Oviewride public String toString() { return "AdressInvoice{" + "link=" + link + ", value=" + value + '}'; } } } 

    Você pode view as classs AdressInvoice e AdressInvoice que combinam atributo e elemento. Você não precisa implementá-los como classs internas; sinta-se livre paira escrevê-los como "normais". Você também não precisa torná-los públicos, mesmo privado é possível (por exemplo, construí-los no construtor da Order .

    Mas observe os construtores vazios sem airgumentos na class Order (e são classs internas). Eles são obrigatórios . Mas você pode torná-los private – sem necessidade de expô-los. É importante que você tenha um construtor sem airgumentos.

    Como usair (exemplo) :

     File f = new File("whateview.xml"); Serializer ser = new Persister(); OrderObject orderObject = ser.read(OrderObject.class, f); System.out.println(orderObject); 

    Este código analisa o Xml do file e imprime o object desserializado.

    Digite Xml (como na sua pergunta) :

     <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <order> <id>1</id> <id_address_deliviewy xlink:href="http://abc.com/add/1">1</id_address_deliviewy> <id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice> </order> </prestashop> <order> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <order> <id>1</id> <id_address_deliviewy xlink:href="http://abc.com/add/1">1</id_address_deliviewy> <id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice> </order> </prestashop> </ order> <prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> <order> <id>1</id> <id_address_deliviewy xlink:href="http://abc.com/add/1">1</id_address_deliviewy> <id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice> </order> </prestashop> 

    Resultado (de println() ) :

     OrderObject{list=[Order{id=1, deliviewy=AdressDeliviewy{link=http://abc.com/add/1, value=1}, invoice=AdressInvoice{link=http://abc.com/add/2, value=2}}]} 

    Não está clairamente representado, mas o suficiente paira view o resultado 🙂

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.