Remove all annotations added into schema by Oracle dbms_xmlschema.registerschema

246 Views Asked by At

I register a schema into Oracle XMLDB via the dbms_xmlschema.registerschema() package sub program.

I then select the registered schema from user_xml_schemas.

The schema returns fine, but Oracle has inserted all sorts of Oracle related information into the schema. Here is an example insert (this is just one of many):

xmlns:oraxdb="http://xmlns.oracle.com/xdb" oraxdb:storeVarrayAsTable="true" oraxdb:flags="2105633" oraxdb:schemaURL="mySchema.xsd" oraxdb:schemaOwner="bob" oraxdb:numProps="22"

This doesn't concern me for use within the database, however I need to provide the schema to consumers outside the database and the Oracle annotations are simply confusing noise for my target external consumers.

What I would like is the ability to achieve something like the following code using my "invented" dbms_xmlschema_annotate.stripAllOracleAnnotations sub program:

begin
  select dbms_xmlschema_annotate.stripAllOracleAnnotations(schema)
  into vMyOriginalPreRegisteredSchema
  from user_xml_schemas;
  ...
end;

so I can provide vMyOriginalPreRegisteredSchema to external consumers.

I have hunted but can't find anything that would return me "the original, clean" schema from xml db.

Any assistance would be greatly appreciated.

NOTE: I tried using XSL transformation to strip out the Oracle annotations but although the XSL file I created works perfectly in XMLSpy, Oracle (18c) completes the transformation without error but returns a completely incorrect result. I tested via xmltransform() and xmltype.transform(). I can only assume this is because Oracle is interpreting the oraxdb: nodes internally and "doing it's own thing".

1

There are 1 best solutions below

0
Pancho On

Although this is NOT my preferred method, as catching all cases via regexp can be error prone, the following appears to work and is the only way I can currently find to achieve what I need:

select regexp_replace(s.schema.getClobVal()
                     ,'( oraxdb:.*?= *".*?"| xmlns:oraxdb="http://xmlns.oracle.com/xdb")',''
                     )
from user_xml_schemas s
where s.schema_url = 'my schema XDB URL';

NOTE: As explained in my question edit, although the following XSL transformation works perfectly in XMLspy and would under normal circumstances be my first choice, it produces incorrect output via Oracle xmltransform() or xmltype.transform() because Oracle appears to pollute the output in the transformation with internal annotations:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:oraxdb="http://xmlns.oracle.com/xdb"
exclude-result-prefixes="oraxdb"
>
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <!-- copy all elements -->
    <xsl:template match="*" priority="-1">
        <xsl:element name="{name()}">
            <xsl:copy-of select="@*[substring(name(),1,7) != 'oraxdb:']"/>
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>

    <!-- Copy all other nodes -->
    <xsl:template match="node()|@*" priority="-2">
        <xsl:copy />
    </xsl:template>

</xsl:stylesheet>

The above XSL approach utilises Remove namespace declaration from XSLT stylesheet with XSLT (because <xsl:copy> does not work with exclude-result-prefixes for removing the xmlns:oraxdb namespace declaration itself).