Page 1 of 1

Cannot validate against schema

Posted: Sat Mar 06, 2010 11:01 pm
by jaql
I have an XML file with dummy data for a mock order and a XSD that I generated through Oxygen along with some data added by me. Of course the data added by me is the problem at the moment.

Oxygen is saying that the data in my XML file is invalid when faced against the regex patterns I have in my schema.

Here's the data from my XML file that is showing up as invalid (specifically: the street, zipcode, phone, accountNumber, and cvv):

Code: Select all


<address>
<street>123 My House Rd.</street>
<state>PA</state>
<zipcode>12345</zipcode>
</address>
<phone>610-123-4567</phone>
<paymentInfo>
<accountName>
<first>Billy</first>
<middleInitial>R</middleInitial>
<last>Bob</last>
</accountName>
<accountNumber>1111999900001111</accountNumber>
<expirationDate>2014-04-12</expirationDate>
<cvv>645</cvv>
</paymentInfo>
Here are the date types I wrote in the XSD:

Code: Select all


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

<xs:simpleType name="idnum">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="999999"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="alphanum">
<xs:restriction base="xs:string">
<xs:pattern value="^[a-zA-Z0-9\s.\-]+$"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="cvv">
<xs:restriction base="xs:integer">
<xs:pattern value="^([0-9]{3,4})$"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="cc">
<xs:restriction base="xs:integer">
<xs:pattern value="^(\d{4}-){3}\d{4}$|^(\d{4} ){3}\d{4}$|^\d{16}$"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="date">
<xs:restriction base="xs:string">
<xs:pattern value="([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="email">
<xs:restriction base="xs:string">
<xs:pattern value="^\w+[\w-\.]*\@\w+((-\w+)|(\w*))\.[a-z]{2,3}$"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="zipcode">
<xs:restriction base="xs:integer">
<xs:pattern value="^[0-9]{5}$"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="phone">
<xs:restriction base="xs:string">
<xs:pattern value="^[2-9]\d{2}-\d{3}-\d{4}$"/>
</xs:restriction>
</xs:simpleType>
Also, Oxygen says my email regex is invalid because "'-' is an invalid character range," which causes the XSD to be invalid as well. I tested all of these regex's and they seem to properly work outside of Oxygen, but I can't get data to validate against them in Oxygen.

Any ideas?

Re: Cannot validate against schema

Posted: Mon Mar 08, 2010 4:50 pm
by adrian
Hello,

Neither Xerces nor Saxon seem to accept the pattern.
You just have to escape the '-' character so it's no longer confused with a character range.

Code: Select all

^\w+[\w\-\.]*
instead of

Code: Select all

^\w+[\w-\.]*
Let me know if you need further help.

Regards,
Adrian

Re: Cannot validate against schema

Posted: Mon Mar 08, 2010 4:56 pm
by adrian
PS:
I also see that '\@' isn't liked by Saxon and since the escaping seems redundant you can simply use '@'.

Re: Cannot validate against schema

Posted: Mon Mar 08, 2010 10:41 pm
by jaql
I actually had to remove all of the ^ and $ characters from each expression. Seems oxygen doesn't like them at all.