Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xsd restriction error when validating xml

Status
Not open for further replies.

rob4733

Programmer
Aug 22, 2017
2
US
Hi All,

Trying to validate xml file, however xsd restriction error results. Data should be valid for this rule though(any number of alphanumeric characters - up to 40 max).

Thoughts? Thx Robert

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:
<?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:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs=" <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>
 
XSD pattern does not support the beginning and end of string anchors. It will probably work as expected by removing the caret and dollar symbols.

Tom Morrison
Consultant
 
Thank You. This works. XSD was from a third party.

Much appreciated.

Robert
 
You are quite welcome, Robert. Welcome to Tek-Tips!

Tom Morrison
Consultant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top