Skip to Main Content

DevOps, CI/CD and Automation

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!

How to add an element with a namespace prefix (Part 2)

GeraudDec 12 2013 — edited Dec 13 2013

Hi all,

I previously asked a question about adding an attribute with a namespace prefix to an element that already exists and that declares the namespace prefix here:

https://forums.oracle.com/thread/2610142

I received an answer that works, but now I am stumped again when I have to add an element where the element name has the namespace prefix.

For example, let's say I already have this element:

<A xmlns="namespace" xmlns:def="myns_namespace"/>

And I want to add this element:

<def:B/>

To produce this:

<A xmlns="namespace" xmlns:def="myns_namespace">

     <def:B/>

</A>

and NOT this:

<A xmlns="namespace" xmlns:def="myns_namespace">

     <def:B xmlns:def="myns_namespace"/>

</A>

This does not work:

SELECT

xmlserialize(document

    appendChildXML(

     xmltype('<A xmlns="namespace" xmlns:def="myns_namespace"/>')

    , '/A'

    , xmlelement("def:D")

    , 'xmlns="namespace" xmlns:def="myns_namespace"'

    )

  indent)

FROM dual;

Because of this error:

ORA-31011: XML parsing failed

ORA-19202: Error occurred in XML processing

LPX-00234: namespace prefix "def" is not declared

Error at line 1

31011. 00000 -  "XML parsing failed"

*Cause:    XML parser returned an error while trying to parse the document.

*Action:   Check if the document to be parsed is valid.

Is there any way to do this without the child element having the duplicate namespace declaration?

My oracle version is:

Oracle Database 11g Release 11.1.0.7.0 - 64bit Production

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 10 2014
Added on Dec 12 2013
3 comments
3,204 views