mortenbra / alexandria-plsql-utils

Oracle PL/SQL Utility Library
784 stars 317 forks source link

Update ora/xml_util_pkg.pkb to fix #27 #59

Open datRedHeadedGuy opened 6 years ago

datRedHeadedGuy commented 6 years ago

Modified the xml_util_pkg and changed the use of XMLType.extract(xpath).getStringVal() to EXTRACTVALUE(XMLType, xpath) so that special characters are not escaped.

mortenbra commented 5 years ago

Hesitant to approve this, as the EXTRACTVALUE function has been deprecated since at least Oracle 11.2 (see https://docs.oracle.com/cd/E11882_01/server.112/e41084/functions061.htm#SQLRF06173 ).

Can you describe the problem in more detail?

eaolson commented 5 years ago

Example:

declare
    x xmltype;
    ex varchar2(100);
begin
    x := xmltype ('<root><foo bar="three &amp; four">one &amp; two</foo></root>');
    ex := xml_util_pkg.extract_value( x, '/root/foo/text()' );
    dbms_output.put_line( ex );
    ex := xml_util_pkg.extract_value( x, '/root/foo/@bar' );
    dbms_output.put_line( ex );
end;

Returns:

one &amp; two
three &amp; four

Wouldn't the expected result have the & unescaped to just "&"? Would calling dbms_xmlgen.convert() be a better solution?