Page 1 of 1

date fromat in xmlGenerator

Posted: Thu Jan 12, 2017 1:20 pm
by magaly
Hi,

I am trying to generate date format from xsd file through xml generator
to do so I am defining the date in XSD.

Code: Select all

                 <xs:simpleType name="myType">
<xs:restriction base="xs:dateTime">
<xs:pattern value="\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\d\d\d"/>
</xs:restriction>
</xs:simpleType>
It actually generates the appropriate date but the document checker raise an error saying that the value of the element is not valid, do you have an Idea of why this error is raised ?

generated date is : <myType>2006-05-04T18:13:51.0</myType>

Regards

Re: date fromat in xmlGenerator

Posted: Thu Jan 12, 2017 6:06 pm
by adrian
Hi,

Check the full error message from the manual validation (Document > Validate >Validate, Ctrl+Shift+V). It explains that the value is invalid with respect to your restriction pattern.
cvc-pattern-valid: Value '2006-05-04T18:13:51.0' is not facet-valid with respect to pattern '\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d\d\d\d' for type
To clarify, your pattern specifies 6 digits for milliseconds (after the last dot), but the XML Generator has generated it as a xs:dateTime and specified just one digit ("0"). It will validate with 6 digits, "000000".

If that was not your intention (to force the use of 6 digits for milliseconds), you can relax the pattern a bit. Replace the trailing "\.\d\d\d\d\d\d" with "\.\d+" (one or more digits).

Regards,
Adrian

Re: date fromat in xmlGenerator

Posted: Fri Jan 13, 2017 11:17 am
by magaly
Hi Adrian,

Thank you for your answer. The thing that I do not understand is that the date I have on xml was generated by Oxygen from the xsd file so why it is not following the given pattern ?
Maybe the restriction is not taken into account ?

Regards,
Magaly

Re: date fromat in xmlGenerator

Posted: Fri Jan 13, 2017 6:09 pm
by adrian
Hi,

Given the example you have provided, you most likely have in Generate Sample XML Files > Options > Settings, "Values of elements and attributes" set to "Default (ignore restrictions)". It should be set to "Random (apply restrictions)".

However, in this case I see it's not working, not even with the correct option being set. The problem seems to be that dateTime is already defining a base pattern for the value and the XML Generator is unable to compose/deduce a single regex pattern (needed for random generation with restrictions) that satisfies both the dateTime pattern and your restriction pattern. It picks the first pattern (dateTime) and uses that.
I've logged this on our issue tracking tool to investigate if there's a way to accommodate this.

Regards,
Adrian

Re: date fromat in xmlGenerator

Posted: Mon Jan 16, 2017 11:18 am
by magaly
Hi Adrian,

Thank's a lot for the attention you have on this topic, let's keep in touch to know what solution the investigations are suggesting.

Regards

Magaly

Re: date fromat in xmlGenerator

Posted: Tue Sep 19, 2017 6:48 pm
by mboivin
Hello,

Are there any development on this issue? I'm facing a similar problem. With the following element definition:

Code: Select all

  <xs:element name="TimeStamp">
<xs:simpleType>
<xs:restriction base="xs:dateTime">
<xs:minInclusive value="2016-01-01T00:00:00"/>
<xs:maxInclusive value="2017-08-31T23:59:59"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
The xmlGenerator generates the following: <TimeStamp>2019-08-07T11:22:04</TimeStamp>.
While this TimeStamp is a valid date and time, it does not follow the min/max inclusive restrictions.

Re: date fromat in xmlGenerator

Posted: Tue Sep 19, 2017 6:57 pm
by adrian
Hi,

There is no development in this regard.
Currently there is no way for the pattern generator to combine the two patterns into one.

Regards,
Adrian