我有下面的xml输出,当父元素具有属性xsi时,我们如何隐藏子元素(endDate):nil = true甚至子元素是nillable = true?
// XML输出
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<snapshots xmlns:xsi="w3.org/2001/XMLSchema-instance"; xmlns:ns3="ws.mycompany.com"; mask="PAC">
<Offers>
<Offer xsi:type="wsMarketingOfferOP" entityId="1234" xsi:nil="true">
<endDate xsi:nil="true"/>
</Offer>
</Offers>
</snapshots>
//快照类
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "OffersElement"})
@XmlRootElement(name = "snapshots")
public class Snapshots<T extends Offer>
{
@XmlElement(name = "Offers")
private OffersElement<T> OffersElement;
public OffersElement<T> getOffersElement() {
return offersElement;
}
public void setOffersElement(OffersElement<T> offersElement) {
this.offersElement = offersElement;
}
}
// OffersElement类
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Offer")
public class OffersElement<T> {
@XmlElementRef(name="Offer")
List<JAXBElement<T>> listOffers;
public List<JAXBElement<T>> getListOffers() {
return listOffers;
}
public void setListMarketOffers(List<JAXBElement<T>> listOffers) {
this.listOffers = listOffers;
}
}
// WSOffer类,其中offer是marshelling,endate nillable设置为true,以便它出现在null的位置。
@XmlRootElement(name = "Offer")
@XmlType(name = "", propOrder = { "endDate" })
@XmlAccessorType(XmlAccessType.FIELD)
public class WSOffer
{
@XmlElement(nillable = true)
protected WSOffer.EndDate endDate;
public WSOffer.EndDate getEndDate() {
return endDate;
}
public void setEndDate(WSOffer.EndDate value) {
this.endDate = value;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "value" })
public static class EndDate
{
@XmlValue
protected Date value;
public Date getValue() {
return value;
}
public void setValue(Date value) {
this.value = value;
}
}
}