我正在尝试使用 jaxb 读取 xml 并尝试创建解析器。我对构建 java bean 的方式和其中的注释有一些疑问。我知道我所做的是错误的,因为我遇到了非法注释错误。
我能否获得一些关于如何编写 bean 和注释以允许 jax b 执行此操作并解析我的 xml 的帮助。
谢谢(对不起,很长的帖子,但希望它会帮助别人)
我简化的 xml 文档看起来像这样......
<WEB-ITM-EXT-REC>
<ACTVTY-CODE>A</ACTVTY-CODE>
<WEB-ITM-EXT-DATA>
<ITEM-NO>93501250080</ITEM-NO>
<PROMOTION-DETAILS>
<PROMOTION-ID></PROMOTION-ID>
<PROMOTION-START-DATE>0</PROMOTION-START-DATE>
<PROMOTION-END-DATE>0</PROMOTION-END-DATE>
<PROMOTION-PRICE>.00</PROMOTION-PRICE>
</PROMOTION-DETAILS>
<NORMAL-SELL-PRICES>
<SELL-PRICE-EFFECTIVE-DATE-1>0</SELL-PRICE-EFFECTIVE-DATE-1>
<SELL-PRICE-1>.00</SELL-PRICE-1>
<SELL-PRICE-EFFECTIVE-DATE-2>0</SELL-PRICE-EFFECTIVE-DATE-2>
<SELL-PRICE-2>.00</SELL-PRICE-2>
<SELL-PRICE-EFFECTIVE-DATE-3>0</SELL-PRICE-EFFECTIVE-DATE-3>
<SELL-PRICE-3>189.95</SELL-PRICE-3>
</NORMAL-SELL-PRICES>
<OUT-OF-STOCK-IND>Y</OUT-OF-STOCK-IND>
</WEB-ITM-EXT-DATA>
</WEB-ITM-EXT-REC>
这是我编写java bean的方式......
@XmlRootElement(name = "WEB-ITM-EXT-REC")
public class ItemDocuments {
@XmlElement(name="ACTVTY-CODE")
private String activityCode;
@XmlElement(name="WEB-ITM-EXT-DATA")
private List<ItemDocument> itemDocuments;
public List<ItemDocument> getItemDocuments() {
return itemDocuments;
}
public void setItemDocuments(List<ItemDocument> itemDocuments) {
this.itemDocuments = itemDocuments;
}
public String getActivityCode() {
return activityCode;
}
public void setActivityCode(String activityCode) {
this.activityCode = activityCode;
}
}
项目豆
@XmlRootElement(name = "WEB-ITM-EXT-DATA")
@XmlAccessorType(XmlAccessType.FIELD)
public class ItemDocument {
@XmlElement(name="ITEM-NO")
private String itemNo;
private PromotionDocument promotion;
private SellPriceDocument sellPrice;
@XmlElement(name="OUT-OF-STOCK-IND")
private String outOfStockInd;
getters..
setters...
}
卖价豆
@XmlType
public class SellPriceDocument {
@XmlElement(name="SELL-PRICE-EFFECTIVE-DATE-1")
private String sellPriceEffectiveDateOne;
@XmlElement(name="SELL-PRICE-1")
private String sellPriceOne;
@XmlElement(name="SELL-PRICE-EFFECTIVE-DATE-2")
private String sellPriceEffectiveDateTwo;
@XmlElement(name="SELL-PRICE-2")
private String sellPriceTwo;
@XmlElement(name="SELL-PRICE-EFFECTIVE-DATE-3")
private String sellPriceEffectiveDateThree;
@XmlElement(name="SELL-PRICE-3")
private String sellPriceThree;
getters..
setters...
}
促销豆
public class PromotionDocument {
@XmlElement(name="PROMOTION-ID")
private String promotionId;
@XmlElement(name="PROMOTION-START-DATE")
private String promotionStartDate;
@XmlElement(name="PROMOTION-END-DATE")
private String promotionEndDate;
@XmlElement(name="PROMOTION-PRICE")
private String promotionPrice;
getters..
setters...
}