[prev in list] [next in list] [prev in thread] [next in thread]
List: xmlbeans-user
Subject: RE: Default values in elements
From: "Radu Preotiuc-Pietro" <radup () bea ! com>
Date: 2006-08-31 18:03:25
Message-ID: 99479F4D39C9244F8E17E688193A3DD8BD7CB6 () repbex02 ! amer ! bea ! com
[Download RAW message or body]
Yes, it is possible, but you need to be aware of a few things.
In XMLSchema, a default value on an element behaves differently than a
default value on an attribute in that an absent element with a default
value does *not* end up as an element with the default value in PSVI,
but an absent attribute with a default value does show up in the PSVI
(also an empty element with default value shows up as an element with
that value).
Keeping this in mind, if you had this in your XML file
<parent>
<testElement/>
</parent>
and you did
parent.getTestElement()
then you would get "1234", the default value.
But if you had
<parent>
</parent>
then parent.getTestElement() would return null.
Radu
________________________________
From: Sriram Vaidyanathan [mailto:Sriram.Vaidyanathan@Copart.Com]
Sent: Wednesday, August 30, 2006 3:30 PM
To: user@xmlbeans.apache.org
Subject: Default values in elements
Hi,
I am new to XMLBeans. Is it possible that the generated XML Bean java
objects can return a default value associated with an element in the
schema?
For eg:
<xsd:simpleType name="mySimpleType">
<xsd:restriction base="xsd:string">
<xsd:maxLength value="4"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="MyComplexType">
<xsd:element name="testElement" type="tns:mySimpleType" default="1234"
minOccurs="0"/>
</xsd:complexType>
So, here suppose that i don't set the testElement value in my client and
send the SOAP message to a service and then on the server side when i do
a getTestElement() , i would expect it to return the default value
"1234". But i get a null instead.
Is there some setting i need to do for getting the default values.?
Thanks for any help on this.
_______________________________________________________________________
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.
[Attachment #3 (text/html)]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2800.1561" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>Yes, it is possible, but you need to be aware of a few
things.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>In XMLSchema, a default value on an element behaves
differently than a default value on an attribute in that an absent element
with a default value does *not* end up as an element with the default value in
PSVI, but an absent attribute with a default value does show up in the PSVI
(also an empty element with default value shows up as an element with that
value).</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>Keeping this in mind, if you had this in your XML
file</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2><parent></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2><testElement/></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></parent></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>and you did</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>parent.getTestElement()</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>then you would get "1234", the default
value.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>But if you had</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2><parent></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></parent></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>then parent.getTestElement() would return
null.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=199334417-31082006><FONT face=Arial
color=#0000ff size=2>Radu</FONT></SPAN></DIV><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> Sriram Vaidyanathan
[mailto:Sriram.Vaidyanathan@Copart.Com] <BR><B>Sent:</B> Wednesday, August 30,
2006 3:30 PM<BR><B>To:</B> user@xmlbeans.apache.org<BR><B>Subject:</B> Default
values in elements<BR></FONT><BR></DIV>
<DIV></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=360570722-30082006>Hi,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=360570722-30082006> I am
new to XMLBeans. Is it possible that the generated XML Bean java objects can
return a default value associated with an element in the
schema?</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=360570722-30082006></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=360570722-30082006>For
eg:</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=360570722-30082006></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=360570722-30082006></SPAN></FONT> </DIV>
<DIV><FONT size=+0><SPAN class=360570722-30082006><FONT color=#008080>
<P align=left><FONT face=Arial size=2><</FONT></FONT><FONT face=Arial><FONT
size=2><FONT color=#3f7f7f>xsd:simpleType </FONT><FONT
color=#7f007f>name</FONT>=<FONT color=#2a00ff>"<SPAN
class=360570722-30082006>mySimple</SPAN>Type"</FONT><FONT
color=#008080>></P></FONT></FONT></FONT>
<P align=left><FONT face=Arial><FONT size=2><FONT color=#008080><</FONT><FONT
color=#3f7f7f>xsd:restriction </FONT><FONT color=#7f007f>base</FONT>=<FONT
color=#2a00ff>"xsd:string"</FONT><FONT
color=#008080>></P></FONT></FONT></FONT>
<P align=left><FONT face=Arial><FONT size=2><FONT color=#008080><</FONT><FONT
color=#3f7f7f>xsd:maxLength </FONT><FONT color=#7f007f>value</FONT>=<FONT
color=#2a00ff>"4"</FONT><FONT color=#008080>/></P></FONT></FONT></FONT>
<P align=left><FONT face=Arial><FONT size=2><FONT
color=#008080></</FONT><FONT color=#3f7f7f>xsd:restriction</FONT><FONT
color=#008080>></P></FONT></FONT></FONT>
<P><FONT face=Arial><FONT size=2><FONT color=#008080></</FONT><FONT
color=#3f7f7f>xsd:simpleType</FONT><FONT
color=#008080>></P></FONT></FONT></FONT></SPAN></FONT></DIV>
<DIV><FONT size=+0><SPAN class=360570722-30082006><FONT color=#008080>
<P><FONT face=Arial size=2></FONT> </P>
<P><FONT face=Arial size=2><</FONT></FONT><FONT face=Arial><FONT size=2><FONT
color=#3f7f7f>xsd:complexType </FONT><FONT color=#7f007f>name</FONT>=<FONT
color=#2a00ff>"<SPAN class=360570722-30082006>MyComplex</SPAN>Type"</FONT><FONT
color=#008080>></FONT></FONT></FONT></P><FONT color=#008080><FONT
color=#008080>
<P><FONT face=Arial size=2><</FONT></FONT><FONT face=Arial><FONT size=2><FONT
color=#3f7f7f>xsd:element </FONT><FONT color=#7f007f>name</FONT><FONT
color=#000000>=</FONT><FONT color=#2a00ff>"<SPAN
class=360570722-30082006>testElement</SPAN>" </FONT><FONT
color=#7f007f>type</FONT><FONT color=#000000>=</FONT><FONT color=#2a00ff>"<SPAN
class=360570722-30082006>tns</SPAN>:<SPAN
class=360570722-30082006>mySimple</SPAN>Type" </FONT><FONT
color=#7f007f>default</FONT><FONT color=#000000>=</FONT><FONT
color=#2a00ff>"<SPAN class=360570722-30082006>1234</SPAN>" </FONT><FONT
color=#7f007f>minOccurs</FONT><FONT color=#000000>=</FONT><FONT
color=#2a00ff>"0"</FONT><FONT
color=#008080>/></P></FONT></FONT></FONT></FONT><FONT size=+0><FONT
size=2><FONT color=#008080><FONT size=2>
<P></FONT><FONT face=Arial><FONT color=#008080 size=2></</FONT><FONT
color=#3f7f7f size=2>xsd:complexType</FONT><FONT color=#008080
size=2>></P></FONT></FONT></FONT></FONT></FONT></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=360570722-30082006>So,
here suppose that i don't set the testElement value in my client and send
the SOAP message to a service and then on the server side when i do
a getTestElement() , i would expect it to return the default value
"1234". But i get a null instead. </SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=360570722-30082006></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=360570722-30082006>Is there some
setting i need to do for getting the default values.?</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=360570722-30082006></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=360570722-30082006> Thanks
for any help on this.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=360570722-30082006></SPAN></FONT> </DIV></BODY></HTML>
<PRE>_______________________________________________________________________
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.
</PRE>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic