Skip to Main Content

Database Software

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

xmltype extract with multiple namespaces returning empty/null values

6bd42ab2-7bed-42aa-9672-b46c9c771a3fMar 18 2015 — edited Mar 19 2015

I cannot get the extract function to return the value in inner nodes when the xml has multiple namespaces

Here is the sample code. I have tried a multitude of namespace parameter values with no luck.

I can retrieve the outer node - presumably because only one namespace applies to this node

declare

     XML_WITH_NS clob;

     LEVEL_1_NODE clob;

     LEVEL_2_NODE clob;

     LEVEL_3_NODE clob;

begin

     XML_WITH_NS :=

          '<Level_1 xmlns="Level_1_Namespace">

             <Level_2 xmlns="Level_2_Namespace">

                 <Level_3>Level 3 data </Level_3>

             </Level_2>

          </Level_1>';

     -- this works

     select extract(xmltype(XML_WITH_NS),'/Level_1','xmlns="Level_1_Namespace"').GETCLOBVAL() into LEVEL_1_NODE from DUAL;

     -- this doesn't work no matter what I put in the namespace

     select extract(xmltype(XML_WITH_NS),'/Level_1/Level_2','xmlns="Level_1_Namespace" xmlns="Level_2_Namespace"').GETCLOBVAL() into LEVEL_2_NODE from DUAL;

     -- this doesn't work no matter what I put in the namespace

     select extract(xmltype(XML_WITH_NS),'/Level_1/Level_2/Level_3').GETCLOBVAL() into LEVEL_3_NODE from DUAL;

     DBMS_OUTPUT.PUT_LINE('XML with Namespaces');

     DBMS_OUTPUT.PUT_LINE('LEVEL_1_NODE : ' || LEVEL_1_NODE);

     DBMS_OUTPUT.PUT_LINE('LEVEL_2_NODE : ' || LEVEL_2_NODE);

     DBMS_OUTPUT.PUT_LINE('LEVEL_3_NODE : ' || LEVEL_3_NODE);

end;

And this is the output

LEVEL_1_NODE : <Level_1 xmlns="Level_1_Namespace"><Level_2 xmlns="Level_2_Namespace"><Level_3>Level 3 data </Level_3></Level_2></Level_1>

LEVEL_2_NODE :

LEVEL_3_NODE :

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 16 2015
Added on Mar 18 2015
1 comment
4,733 views