Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding [CDATA[ element in an XML

User_RFKSXJun 4 2020 — edited Jun 4 2020

Hi,

I was asked to generate an XML, extracting data from a table, but adding the [CDATA[ element.

I have done in the following manner:

select   XMLTYPE

          (

           replace(

           replace(replace(xmlelement("TAG1",

           xmlelement("TAG2",col1),

           xmlelement("TAGX",

           xmlelement("TAG3",

           xmlelement("TAG4",col2)))).extract('/*') ,'/TAGX',']]'),'TAGX','![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?'),

           '<]]>',']]>')

          )

into XMLdoc

from MYTABLE;

where col1 and col2 are MYTABLE's columns

Is it possible to do in a smarter way instead of using the work-around of the REPLACE?

The result should be this:

<TAG1>

<TAG2> 15 </TAG2>

<![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

  <TAG3>

   <TAG4> Rodgers </TAG4>

  </TAG3>

]]>

</TAG1>

Thank you!

Comments
Post Details
Added on Jun 4 2020
3 comments
542 views