Home » SQL & PL/SQL » SQL & PL/SQL » Adding [CDATA[ element in an XML
Adding [CDATA[ element in an XML [message #680729] Thu, 04 June 2020 04:56 Go to next message
Mark70
Messages: 10
Registered: June 2020
Junior Member
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!


Re: Adding [CDATA[ element in an XML [message #680734 is a reply to message #680729] Thu, 04 June 2020 09:42 Go to previous messageGo to next message
Michel Cadot
Messages: 67237
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

And as asked in your previous topic:

Michel Cadot wrote on Wed, 03 June 2020 17:58
...
Note: Always post your Oracle version, with 4 decimals (query v$version), as often solution depends on it.

A feedback in this topic would also be welcome.

Re: Adding [CDATA[ element in an XML [message #680735 is a reply to message #680734] Fri, 05 June 2020 00:40 Go to previous message
_jum
Messages: 571
Registered: February 2008
Senior Member
See https://community.oracle.com/thread/4332272
Previous Topic: How to use table functions
Next Topic: FORALL with associative array and INDEX BY VARCHAR
Goto Forum:
  


Current Time: Thu Jul 09 23:38:30 CDT 2020