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
Messages: 11
Registered: June 2020
Junior Member
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
           xmlelement("TAG4",col2)))).extract('/*') ,'/TAGX',']]'),'TAGX','![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?'),
into XMLdoc
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:

 <TAG2> 15 </TAG2>
 <![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <TAG4> Rodgers </TAG4>
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: 67367
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
Messages: 573
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: Wed Sep 23 02:47:08 CDT 2020