DBMS_XMLSchema.generateSchema can't generate correct XML schema with attributes (Doc ID 1349296.1)

Last updated on AUGUST 29, 2011

Applies to:

Oracle Server - Enterprise Edition - Version: 11.2.0.2.0 and later   [Release: 11.2 and later ]
Information in this document applies to any platform.

Symptoms

DBMS_XMLSchema.generateSchema generates wrong XSD.

Example:
SQL> create or replace type emp_t as object
 2  (
 3   "@id" number(6),
 4   email varchar2(25),
 5   department_id number(4));
 6  /

Type created.

SQL> SELECT DBMS_XMLSchema.generateSchema('XDBTEST', 'EMP_T') as result from dual;

RESULT
--------------------------------------------------------------------------------
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xdb="http://xmlns.oracle.com/xdb"
xsi:schemaLocation="http://xmlns.oracle.com/xdb http://xmlns.oracle.com/xdb/XDBSchema.xsd">
<xsd:element name="EMP_T" type="EMP_TType" xdb:SQLType="EMP_T" xdb:SQLSchema="XDBTEST"/>
<xsd:complexType name="EMP_TType" xdb:SQLType="EMP_T" xdb:SQLSchema="XDBTEST" xdb:maintainDOM="false">
  <xsd:sequence>
    <xsd:element name="_x0040_id" type="xsd:double" xdb:SQLName="@id" xdb:SQLType="NUMBER"/>
    <xsd:element name="EMAIL" xdb:SQLName="EMAIL" xdb:SQLType="VARCHAR2">
      <xsd:simpleType>
       <xsd:restriction base="xsd:string">
        <xsd:maxLength value="25"/>
       </xsd:restriction>
      </xsd:simpleType>
    </xsd:element>
    <xsd:element name="DEPARTMENT_ID" type="xsd:double" xdb:SQLName="DEPARTMENT_ID" xdb:SQLType="NUMBER"/>
  </xsd:sequence>
</xsd:complexType>
</xsd:schema>

This should be an attribute:

<xsd:element name="_x0040_id" type="xsd:double" xdb:SQLName="@id" xdb:SQLType="NUMBER"/>

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