Leading Zeroes Are Not Recognized When Using Schemavalidate On Xml File (Doc ID 466516.1)

Last updated on FEBRUARY 08, 2017

Applies to:

Oracle Server - Enterprise Edition - Version: 10.1.0.2 to 11.1.0.6 - Release: 10.1 to 11.1

Symptoms

When using an xml schema like this

<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2007 rel. 3 sp1 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test_xml">
<xs:complexType>
<xs:sequence>
<xs:element ref="number"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="number">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="10"/>
<xs:pattern value="\d{10}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>


Due to the pattern restriction there have to be 10 digits. But when using schemavalidate, leading
zero's are removed, so the pattern validation fails. The schema is provided by an external entity and cannot  be modified.

Simplified Case :

declare
doc varchar2(3000):= '<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSpy v2007 rel. 3 sp1 (http://www.altova.com)-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="test_xml">
<xs:complexType>
<xs:sequence>
<xs:element ref="number"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="number">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:totalDigits value="10"/>
<xs:pattern value="\d{10}"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>';

declare
the_clob clob;
the_xmltype xmltype;
begin
the_clob := '<?xml version="1.0" encoding="UTF-8"?>
<test_xml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<number>0123456789</number>
</test_xml>';
the_xmltype := xmltype(the_clob);
the_xmltype := the_xmltype.createschemabasedxml('test.xsd');
the_xmltype.schemavalidate();
end;


ORA-31154: invalid XML document
ORA-19202: Error occurred in XML processing
LSX-00333: literal "123456789" is not valid with respect to the pattern
ORA-06512: at "SYS.XMLTYPE", line 345
ORA-06512: at line 11
begin
dbms_xmlschema.registerschema('test.xsd',doc);
end;

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms