You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by "gennady.shumakher" <gs...@gmail.com> on 2008/02/21 14:18:30 UTC

element default value in generated classes

Hi,

I have a default value specified in the definition of the element. But the
generated class returns the default value only if the element exists in the
xml document.
schema:
<complexType name="SomeType">
 <sequence>
    <element name="name" type="string" minOccurs="1"/> 
    <element name="interval" type="long" minOccurs="0" default="1000" /> 
....

xml:
<root>
  <name>AAA</name>
  <interval /> 
...
getInterval() returns default value, but if 'interval' node doesn't exists
in xml (according to minOccurs="0" ) getInterval() returns 0. Is that
designed behavior?

Suppose it is. I do have isxxxSpecified() method to determne the existence
of the element in the document, but whether a way to get programmaticaly the
default value specified in the schema (to prevent its double maintenance in
the schema and in the code)?

Thanks,
Gennady

-- 
View this message in context: http://www.nabble.com/element-default-value-in-generated-classes-tp15611201p15611201.html
Sent from the Xml Beans - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: element default value in generated classes

Posted by Radu Preotiuc-Pietro <ra...@bea.com>.
In XMLSchema, there is a difference between the element not being there
and the element being present, but with the default value. If your
application needs to perform the same action for both cases, you would
have to code this decision in your application. You can avoid
maintaining a separate default value by using the SchemaType API to get
the default value from Schema.

Radu

On Thu, 2008-02-21 at 05:18 -0800, gennady.shumakher wrote:
> Hi,
> 
> I have a default value specified in the definition of the element. But the
> generated class returns the default value only if the element exists in the
> xml document.
> schema:
> <complexType name="SomeType">
>  <sequence>
>     <element name="name" type="string" minOccurs="1"/> 
>     <element name="interval" type="long" minOccurs="0" default="1000" /> 
> ....
> 
> xml:
> <root>
>   <name>AAA</name>
>   <interval /> 
> ...
> getInterval() returns default value, but if 'interval' node doesn't exists
> in xml (according to minOccurs="0" ) getInterval() returns 0. Is that
> designed behavior?
> 
> Suppose it is. I do have isxxxSpecified() method to determne the existence
> of the element in the document, but whether a way to get programmaticaly the
> default value specified in the schema (to prevent its double maintenance in
> the schema and in the code)?
> 
> Thanks,
> Gennady
> 

Notice:  This email message, together with any attachments, may contain information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated entities,  that may be confidential,  proprietary,  copyrighted  and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org