Project

Profile

Help

Undeclared namespace prefix, QName in content

Added by Anonymous almost 15 years ago

Legacy ID: #7994343 Legacy Poster: Pavel Vitkovsky (paolito)

I'm trying to create document with xsi:type attribute with QName in content, but result is not validable. Validator complains about prefix ns not being declared. I'm using non-schema aware Saxon-B 9.1.0.2. Could that be the problem? [code]xquery version "1.0" encoding "UTF-8"; declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; declare namespace ns = "uri"; document { element foo { attribute xsi:type {QName('uri', 'ns:footype')}, element ns:bar {'value'} } } [/code] [code] <ns:bar xmlns:ns="uri">value</ns:bar> [/code]


Replies (1)

RE: Undeclared namespace prefix, QName in content - Added by Anonymous almost 15 years ago

Legacy ID: #7994448 Legacy Poster: Michael Kay (mhkay)

If you generate XML using QNames in content, it's your own responsibility to ensure that the namespace prefixes are declared, Saxon can't do this for you. In XQuery this can sometimes be tricky to achieve, because there is no standard way to output a dynamically-constructed namespace node if the prefix isn't used on any element or attribute. In your example, you could do it by using a direct element constructor in place of the computed element constructor. With Saxon-EE you could do it using the saxon:namespace-node() extension function, or the new XQuery 1.1 namespace constructor expression namespace {"ns"} {"uri" }. The other approach in XQuery 1.0 is highly artificial, but workable: you construct your new content as a child of an element in the ns namespace, and then detach it, taking its in-scope namespaces with it.

    (1-1/1)

    Please register to reply