我正在使用JAXB使用Java对象创建xml。
我正在尝试创建此标签:
<preTaxAmount currency="USD">84</preTaxAmount>
为此,我正在使用以下域类:
public class PreTaxAmount
{
@XmlElement(required = false, nillable = true, name = "content")
private String content;
@XmlElement(required = false, nillable = true, name = "currency")
private String currency;
public String getContent ()
{
return content;
}
public void setContent (String content)
{
this.content = content;
}
public String getCurrency ()
{
return currency;
}
public void setCurrency (String currency)
{
this.currency = currency;
}
}
上面的代码生成以下xml:
<preTaxAmount> <content>380.0</content> <currency>USD</currency> </preTaxAmount>
这种格式与要求的格式有所不同。如何获得所需的格式。
您需要对@XmlAttribute
货币使用注释。这里有类似的问题。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句