1

そのようなフィールドを持つハロークラスを持つ:

private String description;   // a lot of text
private long price;
private int count;

price.. forとcount @XmlAttributeが使用されていることがわかりましたが、 description. なんで?

違いは何ですか?どのように/どこに保存されますか?

4

2 に答える 2

1

IBMのウェブサイトの非常に良い記事

問題の情報自体が要素でマークアップできる場合は、それを要素に入れます。

情報がアトリビュート フォームに適しているが、同じ要素で同じ名前の複数のアトリビュートになる可能性がある場合は、代わりに子要素を使用します。

情報が ID、IDREF、ENTITY などの標準の DTD に似た属性タイプである必要がある場合は、属性を使用します。

情報を空白で正規化しない場合は、要素を使用します。(XML プロセッサは、属性値の生のテキストを変更できる方法で属性を正規化します。)

于 2013-02-26T13:07:42.660 に答える
0

Both XmlElement and @XmlAttribute are quite self-documenting.

@XmlElement will be serialized as an Xml Element (Child node of the current node)

@XmlAttribute will be serialized as an Xml attribute.

knowbody's answer is quite clear about when choose one or the other.

So in your example, you should get something like

<halo price="..." count="..." >
    <description>...</description>
</halo>
于 2013-02-26T13:30:26.137 に答える