Incorrect Result from insertChildXML() for Binary XML When Parent Element is Empty (Doc ID 1078518.1)

Last updated on APRIL 06, 2010

Applies to:

Oracle Server - Enterprise Edition - Version: 11.2.0.0 to 11.2.0.0 - Release: 11.2 to 11.2
Information in this document applies to any platform.

Symptoms

insertChildXML() inserts a child XML element at the wrong node when:
  1. the parent element is EMPTY,
  2. the element has a namespace attribute, and
  3. the XMLTYPE column being modified is stored as a binary XML.
Given the following example:

CREATE TABLE TEST
(
"TEST_ID" VARCHAR2(10) PRIMARY KEY NOT NULL,
"TEST_DOC" XMLType NOT NULL
)
XMLTYPE COLUMN TEST_DOC STORE AS SECUREFILE BINARY XML ALLOW ANYSCHEMA ALLOW NONSCHEMA;

INSERT INTO test VALUES
( 1,'<sm:root xmlns:sm="http://www.test.com/acme"></sm:root>');

commit;

Doing an insertchildxml *appends* the child element instead of inserting it within the root element.

SQL> select test_doc from test where test_id = 1;

TEST_DOC
--------------------------------------------------
<sm:root xmlns:sm="http://www.test.com/acme"/>

SQL> UPDATE TEST
  2    SET TEST_DOC =
  3          insertChildXML
  4                (TEST_DOC,
  5                 '//sm:root',
  6                 'sm:child',
  7                  XMLType('<sm:child xmlns:sm="http://www.test.com/acme"><name>Mary</name></sm:child>'),'xmlns:sm="http://www.test.com/acme"')
  8   WHERE TEST_ID=1;

1 row updated.

SQL> select test_doc from test where test_id = 1;

TEST_DOC
--------------------------------------------------
<sm:root xmlns:sm="http://www.test.com/acme"/>
<sm:child xmlns:sm="http://www.test.com/acme">
  <name>Mary</name>
</sm:child>


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