PLSQL programming skills with Namespaces in XML

Posted on at


As a programmer I had problems with all beautiful namespaces... and as I struggled with them in my code I decided not to use them anymore. So when I receive XML with namespace I just remove them and populate my database without them. How? Like this: You just call my function and VOILA it is gone

FUNCTION F_XML_REMOVE_NAMESPACES(i_xml in xmltype) RETURN XMLTYPE IS
v_xml xmltype default i_xml;
v_xsl varchar2(32767);
BEGIN
v_xsl :=
'<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*">
<!-- remove element prefix (if any) -->
<xsl:element name="{local-name()}">
<!-- process attributes -->
<xsl:for-each select="@*">
<!-- remove attribute prefix (if any) -->
<!-- this if filters out any xmlns="" atts that have no namespace prefix in the xml -->
<xsl:if test="(local-name() != ''xmlns'')">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:if>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>';

RETURN v_xml.transform(xmltype(v_xsl));
END F_XML_REMOVE_NAMESPACES;



About the author

160