allen501pc / jlibs

Automatically exported from code.google.com/p/jlibs
0 stars 0 forks source link

XSInstance does not consider restrictions on xsd types #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
  Create xsd simple type with restriction (for example only digits). Try to generate xml with XSInstance.

What is the expected output? What do you see instead?
  Restriction is ignored.

What version of the product are you using? On what operating system?
  r1753, Windows

Please provide any additional information below.
  <xs:simpleType name="TypeWithRestriction">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{11}"/>
      <xs:maxLength value="11"/>
    </xs:restriction>
  </xs:simpleType>

Original issue reported on code.google.com by kolobo...@gmail.com on 27 Nov 2013 at 8:37

GoogleCodeExporter commented 9 years ago
One can use Xeger (the reverse of regex) to generate valid string that adhere 
to the pattern.
If you want I can provide you with some example code.

Pierre

Original comment by Pierre.v...@gmail.com on 29 Nov 2013 at 7:59

GoogleCodeExporter commented 9 years ago
it supports restrictions.

it supports all facets except pattern;

in your example, you are using pattern facet:
{{{
<xs:pattern value="[0-9]{11}"/>
}}}

Original comment by santhosh.tekuri@gmail.com on 29 Nov 2013 at 9:15

GoogleCodeExporter commented 9 years ago
Hi Pierre,

I looked at Xeger and i liked the project.

there are few concerns in using Xeger:

Concern 1:
given regex, it generates sample string matching that regex.
but it doesn't support generating a sample value of length 11.
because the example provided in issue has:
   <xs:maxLength value="11"/>

Concern 2:
I am not sure whether, the regex syntax supported by this library is same as 
specified in:
http://www.w3.org/TR/xmlschema-2/#rf-pattern

So I think it is not worth using it.

in case you want to make it work as per your requirements:

you can implement XSInstance.SampleValueGenerator interface and supply it as 
below:

XSInstance xsInstance = ...
xsInstance.sampleValueGenerator = new MySampleValueGenerator()

XSInstance.SampleValueGenerator is recently added to jlibs
it is not present in downloads tab. you can get latest build from maven 
snapshot repository or from
https://dl.dropboxusercontent.com/u/326301/jlibs-r1774.zip

Original comment by santhosh.tekuri@gmail.com on 29 Nov 2013 at 9:35