users@jaxb.java.net

Re: Where is my attribute?

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Tue, 21 Jul 2009 13:31:58 +0200

Do you call setFieldBytesLength to set a value?

If you don't, the default defined in the schema applies, and if you
unmarshal or just call getFieldBytesLength(), you'd get that value, i.e.,
zero.

-W


On Mon, Jul 20, 2009 at 6:02 PM, ofira shaer <oshaer_at_gmail.com> wrote:

> Hi.
> I have an attribute that is missing from the resulted xml. What am i doing
> wrong?
>
> schema section:
>
> <xs:complexType name="Field">
> *
>
> <xs:sequence>
> *
>
> <xs:element *ref*="FieldName"/>
>
> <xs:element name="FieldValue" type="xs:string"/>
> *
>
> </xs:sequence>
> *
>
> <xs:attribute name="FieldBytesLength" type="xs:int" default="0"
> use="optional"/>
> </xs:complexType>
>
> generated code:
>
>
> *
>
> public
> class*
> T15Field {
>
> @XmlElement(name = "FieldName", required = *true*)
>
> *protected* String fieldName;
>
> @XmlElement(name = "FieldValue", required = *true*)
>
> *protected* String fieldValue;
>
> @XmlAttribute(name = "FieldBytesLength")
>
> *protected* Integer fieldBytesLength;
>
> .......
>
> /**
>
> * Gets the value of the fieldBytesLength property.
>
> *
>
> * *_at_return
>
> *
>
> * possible object is
>
> * {_at_link Integer }
>
> *
>
> */
>
> *public* *int* getFieldBytesLength() {
>
> *if* (fieldBytesLength == *null*) {
>
> *return* 0;
>
> }
> *else* {
>
> *return* fieldBytesLength;
>
> }
>
> }
>
> /**
>
> * Sets the value of the fieldBytesLength property.
>
> *
>
> * *_at_param* value
>
> * allowed object is
>
> * {_at_link Integer }
>
> *
>
> */
>
> *public* *void* setFieldBytesLength(Integer value) {
>
> *this*.fieldBytesLength = value;
>
> }
>
> }
>
> I instanitiate an object and set the FieldBytesLength value, yet, after
> marshalling I get this:
>
> <Field>
> <FieldName>MY_NAME</FieldName>
> <FieldValue>02</FieldValue>
> </Field>
>
> Where is my attribute?
>
> Thanks.
>
>