My Oracle Support Banner

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

Last updated on MARCH 28, 2019

Applies to:

Oracle Database - Enterprise Edition - Version 11.2.0.2.0 and later
Oracle Database Cloud Schema Service - Version N/A and later
Oracle Database Exadata Cloud Machine - Version N/A and later
Oracle Cloud Infrastructure - Database Service - Version N/A and later
Oracle Database Backup Service - Version N/A 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

To view full details, sign in with your My Oracle Support account.

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


In this Document
Symptoms
Cause
Solution
References


My Oracle Support provides customers with access to over a million knowledge articles and a vibrant support community of peers and Oracle experts.