I have a colleague who needs to convert text from a PL/SQL method into XML compliant text, as he is constructing a excel spreadsheet by updating a text template.
Is there a method in PL/SQL to convert/encode text to XML compliant text?
The DBMS_XMLGEN Package is used to transform results of SQL queries into a canonical XML format.
XMLForest converts each of its argument parameters to XML, and then returns an XML fragment that is the concatenation of these converted arguments. If value_expr is a scalar expression, then you can omit the AS clause, and Oracle Database uses the column name as the element name.
Well, if you just want to convert XML characters, you'll want to do something like...
outgoing_text := DBMS_XMLGEN.CONVERT(incoming_text)
Where outgoing_text
and incoming_text
are both VARCHAR2 or CLOB.
You can specify a second argument, but it defaults to DBMS_XMLGEN.ENTITY_ENCODE
... it can also decode XML entities by passing DBMS_XMLGEN.ENTITY_DECODE
as a second argument.
Later versions of oracle have a built in XML package for manipulating XML data.
For example, is this the sort of thing your colleague wants to do?:
SELECT DBMS_XMLGEN.getXML('SELECT * FROM emp') FROM dual;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With