我正在尝试XML
使用SimpleXML
解析来解析以下内容。
我尝试了不同的方式来解析Attributes
,Element
但无法成功解析下面的 XML。
它会生成一个列在底部的错误。
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<order>
<id>1</id>
<id_address_delivery xlink:href="http://abc.com/add/1">1</id_address_delivery>
<id_address_invoice xlink:href="http://abc.com/add/2">2</id_address_invoice>
</order>
</prestashop>
Order.java
@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_delivery",required=false)
private int id_address_delivery;
@Attribute( name="href", required=false)
private String id_address_delivery_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;
}
}
我得到的例外是:
WARN/System.err(988): org.simpleframework.xml.core.PersistenceException:
Duplicate annotation of name 'href' on field 'id_address_delivery_href'
private java.lang.String com.prestashop.orders.Order.id_address_delivery_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)
.
.