I have a very simple problem, but I think I am going about it the wrong way.
I have the following XMLTYPE variable in pl/sql:
<A xmlns="namespace" xmlns:def="myns_namespace">
<B/>
</A>
In a separate step, I would like to add the following element after B:
<C attr="attribute" def:defattr="def_attribute"/>
To produce the following xml:
<A xmlns="namespace" xmlns:def="myns_namespace">
<B/>
<C attr="attribute" def:defattr="def_attribute"/>
</A>
What is the best way to do this? I have tried the following:
1. The following fails because when creating the C element, oracle complains 'namespace prefix "def" is not declared. This makes sense.
SELECT
insertChildXML(
eltA,
'/A/B',
'C',
xmlElement("C", xmlAttributes('attribute' "attr", 'def:defattr' "def_attribute")),
'xmlns="namespace" xmlns:def="myns_namespace"'
)
INTO ...
2. I've also tried creating element C with the namespace attributes before adding to element A and then removing the namespace declaration attributes using deleteXML. This does not work because apparently the function can delete Attributes, but it cannot delete namespace declarations. I am trying to avoid ending up with this:
<A xmlns="namespace" xmlns:def="myns_namespace">
<B/>
<C xmlns="namespace" xmlns:def="myns_namespace" attr="attribute" def:defattr="def_attribute"/>
</A>
I was hoping to find a function that could do any one of the following:
1. Create element fragments, ignoring namespace prefixes and not throw an error.
2. Remove specific namespace declarations or any redundant namespace declarations.
3. Add a child element some other way in which the child element would not need to be created and validated independently before being added to the parent.
4. Or maybe I am going about this whole xml creation process the wrong way and need to rethink my strategy?