, ,

How to add, change and remove namespace in xml in ORACLE DB

вторник, 12 октября 2010 г. Оставить комментарий

Add namespace, method 1:


select insertchildxml(xmltype('<a id="a1"><b id="b1">bbb_value<!-- dummy --></b></a>'),
'/a',
'@xmlns',
'http://www.my.com/scheme')
from dual;

Result:


<a id="a1" xmlns="http://www.my.com/scheme"><b id="b1">bbb_value<!-- dummy --></b></a>

Add namespace, method 2:


select xmltransform(
xmltype('<a id="a1"><b id="b1">bbb_value<!-- dummy --></b></a>'),
xmltype(
'<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.my.com/scheme">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="processing-instruction()|comment()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
')
).getclobval()
from dual;

Result:


<?xml version="1.0" encoding="utf-8"?>
<a xmlns="http://www.my.com/scheme" id="a1">
<b id="b1">bbb_value<!-- dummy --></b>
</a>

Update namespace:


select xmltransform(
xmltype('<a xmlns="http://www.my.com/scheme_old" id="a1"><b id="b1">bbb_value<!-- dummy --></b></a>'),
xmltype(
'<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.my.com/scheme">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="processing-instruction()|comment()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
')
)
from dual;

Result:


<?xml version="1.0" encoding="utf-8"?>
<a xmlns="http://www.my.com/scheme" id="a1">
<b id="b1">bbb_value<!-- dummy --></b>
</a>

Delete namespace:


select xmltransform(
xmltype('<a xmlns="http://www.my.com/scheme_old" id="a1"><b id="b1">bbb_value<!-- dummy --></b></a>'),
xmltype(
'<?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" indent="yes"/>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*" />
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="processing-instruction()|comment()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
')
)
from dual;

Result:


<?xml version="1.0" encoding="utf-8"?>
<a id="a1">
<b id="b1">bbb_value<!-- dummy --></b>
</a>

0 коммент. »

Оставьте Ваш комментарий