[xquery-talk] Omit namespace attributes in output file

Michael Kay mike at saxonica.com
Wed Apr 19 03:28:16 PDT 2017

Sorry, but the XPath/XQuery data model has no way of representing an element node whose name has an undeclared prefix. XPath and XQuery work only with namespace-well-formed XML.

If you really need this badly enough, you could either

(a) post-process the serialized XML to strip off the namespace declarations (e.g. with a non-XML tool such as sed or awk), or

(b) customize the Saxon serializer. Subclass net.sf.saxon.serialize.XMLEmitter to override the namespace() method, subclass net.sf.saxon.lib.SerializerFactory overriding the newXMLEmitter() method to instantiate your XMLEmitter subclass, and nominate your subclassed SerializerFactory using Configuration.setSerializerFactory() - not actually that difficult if you're comfortable with Java programming.

Michael Kay

> On 19 Apr 2017, at 11:10, xquery at docbook-autor.de wrote:
> Hi,
>> XQuery output has to be well-formed (and namespace-well-formed) XML,
>> so you can't output an element name like <ac:emoticon> unless the
>> "ac" prefix is declared and bound to a namespace URI. Why would you
>> want to? Does Confluence really use non-namespace-aware XML?
> my xml output file will be some Confluence wiki page saved as file on
> the server so Confluence will load it on its next start-up.
> Inside Clonfluence the namespace "ac" surely will be well-formed but
> that is part of the higher-level "frame" where my xml file is loaded into.
> BTW: The Confluence Storage Format for wiki pages uses all its
> namespaces without namespace declaration inside the respective wiki page
> itself. That seems to be part of the Confluence framework.
> It is correct to demand the declaration of namespaces. I do not question
> that. But with
> declare option saxon:output "omit-xml-declaration=yes";
> I can omit the xml declaration at the beginning of the xml output file.
> I need some parameter/option to omit every namespace declaration.
> Kind of:
> declare option saxon:output "omit-all-ns-declaration=yes";
> So I declare the following namespace as I do it now:
> declare namespace ac="https://www.atlassian.com/schema/confluence/6/ac";
> If not there will be an error message due to a missing namespace
> declaration.
> But the option above would leave the Confluence namespaced tags in my
> output file as they are:
> <ac:emoticon ac:name="warning"/>
> Is there a possibility to achieve this with XQuery or Saxon?
> Best regards from Germany
>  Michael
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk

More information about the talk mailing list