Validating XML against XSD - restriction error

Questions about XML that are not covered by the other forums should go here.
rob4732
Posts: 2
Joined: Tue Aug 22, 2017 6:27 pm

Validating XML against XSD - restriction error

Post by rob4732 » Tue Aug 22, 2017 6:33 pm

Hi All,

Attempting to validate xml against xsd, but getting restriction error(even though data appears to be valid for that restriction pattern). If I understand the restriction correctly, it should allow a max of 40 alphanumeric characters.

Thoughts? Thx Robert

Validation Error:
ERROR: Element 'patient-id': [facet 'pattern'] The value 'str1234' is not accepted by the pattern '^[a-zA-Z0-9]+$'.
ERROR: Element 'patient-id': 'str1234' is not a valid value of the local atomic type.

XML:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<submission type="OUTPATIENT" data="str1234" version="123.45" action-code="ADD">
<provider>
<provider-id>str123</provider-id>
<npi>str1234</npi>
<patient>
<birthdate>08-01-2016</birthdate>
<sex>str1234</sex>
<race>str1234</race>
<ethnic>str1234</ethnic>
<postal-code>str1234</postal-code>
<attesting_physician_code>str1234</attesting_physician_code>
<attesting_physician_specialty_code>str1234</attesting_physician_specialty_code>
<principal_procedure_physician_code>str1234</principal_procedure_physician_code>
<first-name>str1234</first-name>
<last-name>str1234</last-name>
<encounter measure-set="str1234">
<encounter-date>08-01-2016</encounter-date>
<arrival-time>str1234</arrival-time>
<patient-id>str1234</patient-id>
<medical-record-number>str1234</medical-record-number>
<pthic>str1234</pthic>
<detail answer-code="str1234" row-number="1234" question-cd="str1234">
<answer-value>str1234</answer-value>
</detail>
</encounter>
</patient>
</provider>
</submission>
XSD:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="submission">
<xs:complexType>
<xs:sequence>
<xs:element name="provider" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="provider-id" minOccurs="1" maxOccurs="1" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="6" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="npi" type="xs:string" maxOccurs="1" minOccurs="0" />
<xs:element name="patient" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="birthdate" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])-([0-9][0-9][0-9][0-9])"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="sex" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="race" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="ethnic" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="postal-code" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="attesting_physician_code" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="attesting_physician_specialty_code" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="principal_procedure_physician_code" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="first-name" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="last-name" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="encounter" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="encounter-date" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])-([0-9][0-9][0-9][0-9])"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="arrival-time" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="8"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="patient-id" minOccurs="1" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="40"/>
<xs:pattern value="^[a-zA-Z0-9]+$"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="medical-record-number" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="15"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="pthic" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element maxOccurs="unbounded" name="detail" minOccurs="0">
<xs:complexType>
<xs:sequence minOccurs="0">
<xs:element name="answer-value" type="xs:string" />
</xs:sequence>
<xs:attribute name="answer-code" type="xs:string" use="required" />
<xs:attribute name="row-number" type="xs:integer" use="required" />
<xs:attribute name="question-cd" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="measure-set" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="OUTPATIENT"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="data" type="xs:string" use="required" />
<xs:attribute name="version" type="xs:decimal" use="required" />
<xs:attribute name="action-code" use="required" >
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ADD"/>
<xs:enumeration value="DELETE"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>

adrian
Posts: 2515
Joined: Tue May 17, 2005 4:01 pm

Re: Validating XML against XSD - restriction error

Post by adrian » Tue Aug 22, 2017 7:39 pm

Hi,

Is this your schema, or you have it from somewhere?
The problem is caused by the ^ and $ special characters which cause the pattern matching to fail. It works just fine with just [a-zA-Z0-9]+.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

rob4732
Posts: 2
Joined: Tue Aug 22, 2017 6:27 pm

Re: Validating XML against XSD - restriction error

Post by rob4732 » Tue Aug 22, 2017 7:46 pm

Excellent. Thank you. This XSD is from a third party. Validation is working without ^ and $.

Robert

Post Reply