Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 82 additions & 2 deletions ora/xml_util_pkg.pkb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ as
Who Date Description
------ ---------- -------------------------------------
FDL 03.05.2007 Created
JMW 07.11.2025 Added get_unescaped_string()
so that special characters
in the return value are not escaped

*/

Expand Down Expand Up @@ -159,6 +162,76 @@ begin
end get_string;


function get_unescaped_string( p_escaped in varchar2 ) return varchar2
as
l_returnvalue string_util_pkg.t_max_pl_varchar2;
l_pos pls_integer;
l_end pls_integer;
l_entity varchar2(50);
l_code pls_integer;
l_char varchar2(10);
begin

/*

Purpose: get unescaped string

Remarks:

Who Date Description
------ ---------- --------------------------------
JMW 07.11.2025 Created

*/

l_returnvalue := p_escaped;

-- Replace standard XML entities
l_returnvalue := replace(l_returnvalue, '&', '&');
l_returnvalue := replace(l_returnvalue, '&lt;', '<');
l_returnvalue := replace(l_returnvalue, '&gt;', '>');
l_returnvalue := replace(l_returnvalue, '&quot;', '"');
l_returnvalue := replace(l_returnvalue, '&apos;', '''');

-- Handle numeric character references (decimal and hex)
l_pos := instr(l_returnvalue, '&#');
while l_pos > 0 loop
l_end := instr(l_returnvalue, ';', l_pos);
exit when l_end = 0;

l_entity := substr(l_returnvalue, l_pos + 2, l_end - l_pos - 2);

begin
if lower(substr(l_entity, 1, 1)) = 'x' then
-- Hexadecimal reference
l_code := to_number(substr(l_entity, 2), 'xxxx');
else
-- Decimal reference
l_code := to_number(l_entity);
end if;

-- Convert code point to character safely
if l_code between 0 and 255 then
l_char := chr(l_code);
else
-- Use Unicode escape for high code points
l_char := unistr('\'+lpad(to_char(l_code, 'xxxx'),4,'0')); --'
end if;

-- Replace the entity in the string
l_returnvalue := substr(l_returnvalue, 1, l_pos - 1) || l_char || substr(l_returnvalue, l_end + 1);
exception
when others then
-- If numeric conversion fails, leave entity as-is
l_end := l_pos;
end;
l_pos := instr(l_returnvalue, '&#', l_pos + length(l_char));
end loop;

return l_returnvalue;
end get_unescaped_string;


function tag_str (p_str in varchar2,
p_tag_name in varchar2) return varchar2
as
Expand Down Expand Up @@ -303,6 +376,9 @@ begin
Who Date Description
------ ---------- -------------------------------------
MBR 07.12.2010 Created
JMW 07.11.2025 Added get_unescaped_string()
so that special characters
in the return value are not escaped

*/

Expand All @@ -315,7 +391,7 @@ begin
l_returnvalue := null;
end;

l_returnvalue := nvl(l_returnvalue, p_default_value);
l_returnvalue := nvl(get_unescaped_string(l_returnvalue), p_default_value);

return l_returnvalue;

Expand All @@ -339,11 +415,14 @@ begin
Who Date Description
------ ---------- --------------------------------
MBR 27.01.2011 Created
JMW 07.11.2025 Added get_unescaped_string()
so that special characters
in the return value are not escaped

*/

begin
l_returnvalue := p_xml.extract(p_xpath, p_namespace).getstringval();
l_returnvalue := get_unescaped_string(p_xml.extract(p_xpath, p_namespace).getstringval());
exception
when others then
l_returnvalue := p_default_value;
Expand Down Expand Up @@ -426,3 +505,4 @@ end extract_value_number;

end xml_util_pkg;
/

12 changes: 10 additions & 2 deletions ora/xml_util_pkg.pks
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ as
Who Date Description
------ ---------- -------------------------------------
FDL 03.05.2007 Created
JMW 07.11.2025 Added get_unescaped_string()
so that special characters
in the return value are not escaped

*/

Expand Down Expand Up @@ -37,12 +40,15 @@ as
p_name in varchar2,
p_regional_settings in t_regional_settings := null,
p_raise_error_if_parse_error in boolean := false) return number;

-- return a string from DOM node
function get_string (p_node in dbms_xmldom.domnode,
p_name in varchar2,
p_trim_str in boolean := true) return varchar2;


-- get unescaped string
function get_unescaped_string( p_escaped in varchar2 ) return varchar2;

-- build tagged string
function tag_str (p_str in varchar2,
p_tag_name in varchar2) return varchar2;
Expand Down Expand Up @@ -81,3 +87,5 @@ as
end xml_util_pkg;
/