Xml text with prefix and element in-scope namespace declaration

40 views Asked by At

Can anybody help me to understand the meaning/usage of prefix in text node?

I need to create an element in the OSB xquery like this <faultcode xmlns:http="http://blah.blah.com/dynamicValue">http:fault400</faultcode>

I know how to create an element with QName but I can't add in-scope namespace declaration. So my code is obviously incorrect:

element{
    QName( concat("http="http://blah.blah.com/",$dynamicValue), "faultcode")
    }{"http:fault400"}

returns

<http:faultcode xmlns:http="http://blah.blah.com/dynamicValue">http:fault400</faultcode>

Placing QName into element doesn't produce any declarations:

element{
     "faultcode"
    }{QName( concat("http="http://blah.blah.com/",$dynamicValue),"http:fault400")}
<faultcode>http:fault400</faultcode>

This is essential that the the namespace What's the reasoning behind using such "qualified text" and how to produce this element in xquery?

Upd: environment - Oracle Service Bus 12c, XQuery 1.0

1

There are 1 answers

1
Michael Kay On

If the element name is known statically, then you can use a direct element constructor rather than a computed element constructor, and this enables you to add the namespace binding directly: create the element using

<faultcode xmlns:http="http://blah.blah.com/dynamicValue">http:fault400</faultcode>

In XQuery 3.1 you can also achieve this with a computed element constructor, by using a namespace constructor:

element{"faultcode"} {
    namespace http {"http://blah.blah.com/dynamicValue"}, 
    "http:fault400"}

You mention OSB, I'm not familiar with that technology and I don't know if it imposes particular constraints or provides additional options.

As for "understanding the meaning/usage of [the] prefix", it's not uncommon for XML vocabularies to use QNames in the content of elements and attributes - the main examples of vocabularies that do so are XSLT and XSD. But I don't have any insights into what the designers of this particular vocabulary were trying to achieve.