DBMS_XMLDOM.getlength Returns Wrong Value for Content with Whitespace within a Node Element (Doc ID 1298289.1)

Last updated on FEBRUARY 23, 2011

Applies to:

Oracle Server - Enterprise Edition - Version: 10.2.0.5 and later   [Release: 10.2 and later ]
Information in this document applies to any platform.

Symptoms

Since database upgrade from 10.2.0.4 to 10.2.0.5 the function DBMS_XMLDOM.GETLENGTH returns the value 1 used on empty XML-Elements.
Used on a structure like '<Paket><bf></bf></Paket> it returns 0 when counting the childs of <bf>.
If you insert a blank between <bf> and </bf> it return 1.

--
-- 10.2.0.5 and 11.2.0.2
--
set serveroutput on

declare
doc DBMS_XMLDOM.domdocument := NULL;
paket_el DBMS_XMLDOM.domelement;
nachricht_nl DBMS_XMLDOM.domnodelist;
nachricht_node DBMS_XMLDOM.domnode;
nachricht_el DBMS_XMLDOM.domelement;
zaehler NUMBER;
BEGIN
doc := DBMS_XMLDOM.newdomdocument (xmltype('<Paket><bf></bf></Paket>'));
paket_el := DBMS_XMLDOM.getdocumentelement (doc);
nachricht_nl := DBMS_XMLDOM.getelementsbytagname (paket_el, 'bf');
nachricht_nl :=
DBMS_XMLDOM.getchildnodes (DBMS_XMLDOM.item (nachricht_nl, 0));
zaehler := DBMS_XMLDOM.getlength (nachricht_nl);
dbms_output.put_line('Count without blanks: ' || zaehler);
doc := DBMS_XMLDOM.newdomdocument (xmltype('<Paket><bf> </bf></Paket>'));
paket_el := DBMS_XMLDOM.getdocumentelement (doc);
nachricht_nl := DBMS_XMLDOM.getelementsbytagname (paket_el, 'bf');
nachricht_nl :=
DBMS_XMLDOM.getchildnodes (DBMS_XMLDOM.item (nachricht_nl, 0));
zaehler := DBMS_XMLDOM.getlength (nachricht_nl);
dbms_output.put_line('Count with blank: ' || zaehler);
END;
/

Count without blanks: 0
Count with blank: 1

PL/SQL procedure successfully completed.

Doing the same with a database of version 10.2.0.4 or 11.1.0.7 we got in both cases the value 0.

--
-- 10.2.0.4 and 11.1.0.7
--
set serveroutput on

declare
doc DBMS_XMLDOM.domdocument := NULL;
paket_el DBMS_XMLDOM.domelement;
nachricht_nl DBMS_XMLDOM.domnodelist;
nachricht_node DBMS_XMLDOM.domnode;
nachricht_el DBMS_XMLDOM.domelement;
zaehler NUMBER;
BEGIN
doc := DBMS_XMLDOM.newdomdocument (xmltype('<Paket><bf></bf></Paket>'));
paket_el := DBMS_XMLDOM.getdocumentelement (doc);
nachricht_nl := DBMS_XMLDOM.getelementsbytagname (paket_el, 'bf');
nachricht_nl :=
DBMS_XMLDOM.getchildnodes (DBMS_XMLDOM.item (nachricht_nl, 0));
zaehler := DBMS_XMLDOM.getlength (nachricht_nl);
dbms_output.put_line('Count without blanks: ' || zaehler);
doc := DBMS_XMLDOM.newdomdocument (xmltype('<Paket><bf> </bf></Paket>'));
paket_el := DBMS_XMLDOM.getdocumentelement (doc);
nachricht_nl := DBMS_XMLDOM.getelementsbytagname (paket_el, 'bf');
nachricht_nl :=
DBMS_XMLDOM.getchildnodes (DBMS_XMLDOM.item (nachricht_nl, 0));
zaehler := DBMS_XMLDOM.getlength (nachricht_nl);
dbms_output.put_line('Count with blank: ' || zaehler);
END;
/

Count without blanks: 0
Count with blank: 0

PL/SQL procedure successfully completed.

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms