users@jaxb.java.net

Q: Does JAXB handle elements with minOccurs="0" correctly?

From: Jacob Lauemøller <jacob.lauemoeller_at_computer.org>
Date: Wed, 17 Nov 2004 21:39:24 +0100

Hi all,

Suppose I have an XML Schema with (among others) a declaration like

  <xs:complexType name="foobar">
    <xs:sequence>
      <xs:element name="a" type="xs:int"/>
      <xs:element name="b" type="xs:int" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

From this, JAXB generates the interface Foobar

public interface Foobar {
    int getA();
    void setA(int value);
    int getB();
    void setB(int value);
}

with a matching implementation in FoobarImpl. When I unmarshal XML documents
based on this schema they will always contain an <a> element and may or may
not contain a <b> element.

My question is: Given a Foobar instance, how do I determine wether or not
element <b> occurred in a document?

FYI, for the same schema, Apache Axis will generate a Java class for <foobar>
which maps <b> to java.lang.Integer, allowing the getter to return null when
<b> does not occur in the unmarshalled document.

Kind regards,
Jacob

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net