Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Web Services and the fly likes data constraint does not work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "data constraint does not work" Watch "data constraint does not work" New topic
Author

data constraint does not work

jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
Hi

i have the following data constraints:

<xs:simpleType name="CHAR1_TYPE">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="1"/>
</xs:restriction>
</xs:simpleType>

it is applied to my .xsd schema.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:tns="http://yang.tao/Test" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://yang.tao/Test" version="1.0">
<xs:include schemaLocation="datatype.xsd"/>
<xs:element name="getPersonInfo" type="tns:personInfo" nillable="true"/>
<xs:element name="getPersonInfoResponse" type="xs:string" nillable="true"/>
<xs:complexType name="personInfo">
<xs:sequence>
<xs:element name="firstName" type="tns:CHAR1_TYPE"/>
<xs:element name="lastName" type="tns:CHAR10_TYPE"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

but when i run the web service , i am still able to input more than one chars, can anyone please tell me how to make the constraints work?
sarbjeet sidhu
Greenhorn

Joined: Jan 24, 2010
Posts: 11
Hi,

Try the following, this should work.


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:tns="http://yang.tao/Test" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://yang.tao/Test" version="1.0">
<xs:include schemaLocation="datatype.xsd"/>
<xs:element name="getPersonInfo" type="tns:personInfo" nillable="true"/>
<xs:element name="getPersonInfoResponse" type="xs:string" nillable="true"/>
<xs:complexType name="personInfo">
<xs:sequence>
<xs:element name="firstName" nillable="true">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xs:element name="lastName" nillable="true">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="20" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xs:sequence>
</xs:complexType>
</xs:schema>

Thanks
:thumbup:
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
thank you for help

but i need a separate file to contains all the data constraints so that they are reusable.

can you give me some suggestions?
jim li
Ranch Hand

Joined: May 20, 2008
Posts: 180
i pointed my web service to the existing wsdl file with the data constraints, but it does not throw any exception , can anyone tell me why>?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: data constraint does not work