File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes how to allow empty values in XML Schema elements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how to allow empty values in XML Schema elements" Watch "how to allow empty values in XML Schema elements" New topic
Author

how to allow empty values in XML Schema elements

vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Hi
In the following XML Schema the elements RID and BID it should allow empty values.

<xs:element name="CustomerCode">
<xs:complexType>
<xs:sequence>
<xs:element name="RID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9]{15}" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="BID">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="[A-Z0-9]{15}" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

Could any body please tell me how to do that

Thanks
Vamshi


Thanks,
Vamshidhar Nimbagiri
SCJP 5.0
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
You have to include "minOccurs" attribute in the element tag with "0" as the value.

<xs:element name="RID" minOccurs="0">
vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Hi Purushotham,

Thanks for the reply,

If i include minOccurs="0" the element RID may be ommitted
but here in my case the content of the RID may be empty so i have to handle even if
the content in RID element is empty value.
could you please tell me how to handle this?

Thanks
Vamshi
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Sorry I didn't get right in the first reply. You need to use nillable="true" attribute as well for the respective elements.
vamshidhar nimbagiri
Ranch Hand

Joined: Oct 04, 2004
Posts: 61
Thanks Purushotham!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to allow empty values in XML Schema elements