Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XSInstance does not consider restrictions on xsd types #43

Open
GoogleCodeExporter opened this issue Mar 14, 2015 · 5 comments
Open

XSInstance does not consider restrictions on xsd types #43

GoogleCodeExporter opened this issue Mar 14, 2015 · 5 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 27 Nov 2013 at 8:37

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 29 Nov 2013 at 7:59

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 29 Nov 2013 at 9:15

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 29 Nov 2013 at 9:35

@IsraSmida
Copy link

I have the same problem pattern restrictions are ignored here is a sample of the xsd file :

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="errors">
        <xs:complexType>
            <xs:attribute name="type" type="new1" />
        </xs:complexType>
    </xs:element>

    <xs:element name="error">
        <xs:complexType>
            <xs:attribute name="number" type="new2" />
        </xs:complexType>
    </xs:element>

    <xs:simpleType name='new1'>
        <xs:restriction base='xs:string'>
            <xs:pattern value='(string|int|double|float)' />
        </xs:restriction>
    </xs:simpleType>

    <xs:simpleType name='new2'>
        <xs:restriction base='xs:string'>
            <xs:pattern value='error#\d' />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

The generated files :

<?xml version="1.0" encoding="UTF-8"?>
<!--@(number?)-->
<error number="number1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

cvc-pattern-valid: Value 'number1' is not facet-valid with respect to pattern 'error#\d' for type 'new2'.

<?xml version="1.0" encoding="UTF-8"?>
<!--@(type?)-->
<errors type="type1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>

cvc-pattern-valid: Value 'type1' is not facet-valid with respect to pattern '(string|int|double|float)' for type 'new1'.

@santhosh-tekuri
Copy link
Owner

patterns are not supported by XSInstance. It is not trivial, given a regex-pattern, generate sample input matching that regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants