| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.misc -> Re: XMLType problem
"Bruno D." <bdurren_avirer__at_hotmail.com> wrote in message news:<40743139$0$19647$4d4eb98e_at_read.news.fr.uu.net>...
> Hi everyone,
>
> Under oracle 9.2i if you execute this:
>
> select xmltype('<tag>It''s
> cool</tag>').extract('//tag/text()').GetStringVal() from dual;
>
> you get: It's cool
>
> The question is simple: How to get --> It's cool ????
>
> Thanks in advance for any response.
Bruno,
You are going to have create a local function to do the decoding of the XML text. This is true for 9.2.0.1 and 10.1.0.2.
According to p.85-7 of the "Oracle9 iSupplied PL/SQL Packages and Types Reference" manual, there is a second parameter (FLAG) to the DBMS_XMLGEN.CONVERT function which determines whether encoding or decoding is done. The default is to encode.
In theory, one should be able to do the following: SELECT
DBMS_XMLGEN.convert(
XMLTYPE(
'<tag>It''s cool</tag>'
).extract(
'//tag/text()'
).GetStringVal(),
DBMS_XMLGEN.ENTITY_DECODE
)
FROM
dual
However in 9.2.0.1 and 10.1.0.2, the following error message appears:
DBMS_XMLGEN.ENTITY_DECODE
*
To get around this, I created a function to wrap the CONVERT function:
CREATE OR REPLACE FUNCTION
xml_decode(
i_xml_string IN VARCHAR2
)
RETURN VARCHAR2
IS
BEGIN
RETURN
DBMS_XMLGEN.convert(
i_xml_string,
DBMS_XMLGEN.ENTITY_DECODE
);
And I modify the query as follows to call my new function:
SELECT
xml_decode(
XMLTYPE(
'<tag>It''s cool</tag>'
).extract(
'//tag/text()'
).GetStringVal()
)
FROM
dual
I get the following result:
XML_DECODE(XMLTYPE('<TAG>IT''SCOOL</TAG>').EXTRACT('//TAG/TEXT()').GETSTRING
VAL(
Which is what you want.
Douglas Hawthorne Received on Wed Apr 07 2004 - 22:10:38 CDT
![]() |
![]() |