Discussion:
[xquery-talk] Omit namespace attributes in output file
x***@docbook-autor.de
2017-04-19 08:51:57 UTC
Permalink
Hi,

I’m transforming some DocBook data into an XML file using XQuery. The
transformation works perfectly so far.

My problem is, that I have to use some confluence namespace tags like
<ac:emoticon ac:name=“warning” /> in the XML output file.

So I have to declare the respective namespace at the beginning of my
XQuery file:

###
xquery version "1.0" encoding "utf-8";

declare namespace db="http://docbook.org/ns/docbook";
declare namespace saxon="http://saxon.sf.net/";
declare namespace ac="https://www.atlassian.com/schema/confluence/6/ac";

declare option saxon:output "version=1.0";
declare option saxon:output "omit-xml-declaration=yes";
declare option saxon:output "indent=yes";
###

Because of the namespace declaration for "ac" at the beginning the
transformation results in this:

###
<ac:emoticon xmlns:ac="https://www.atlassian.com/schema/confluence/6/ac"
ac:name="warning"/>
###

Without this declaration the transformation stops with an error message
that a declaration for namespace “ac” is missing.

Is it possible to omit the xmlns:ac attribute somehow?

Thanks in advance!

Regards
Michael
_______________________________________________
***@x-query.com
http://x-q
Michael Kay
2017-04-19 09:38:31 UTC
Permalink
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?

Michael Kay
Saxonica
Post by x***@docbook-autor.de
Hi,
I’m transforming some DocBook data into an XML file using XQuery. The
transformation works perfectly so far.
My problem is, that I have to use some confluence namespace tags like
<ac:emoticon ac:name=“warning” /> in the XML output file.
So I have to declare the respective namespace at the beginning of my
###
xquery version "1.0" encoding "utf-8";
declare namespace db="http://docbook.org/ns/docbook";
declare namespace saxon="http://saxon.sf.net/";
declare namespace ac="https://www.atlassian.com/schema/confluence/6/ac";
declare option saxon:output "version=1.0";
declare option saxon:output "omit-xml-declaration=yes";
declare option saxon:output "indent=yes";
###
Because of the namespace declaration for "ac" at the beginning the
###
<ac:emoticon xmlns:ac="https://www.atlassian.com/schema/confluence/6/ac"
ac:name="warning"/>
###
Without this declaration the transformation stops with an error message
that a declaration for namespace “ac” is missing.
Is it possible to omit the xmlns:ac attribute somehow?
Thanks in advance!
Regards
Michael
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/
x***@docbook-autor.de
2017-04-19 10:10:51 UTC
Permalink
Hi,
Post by Michael Kay
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
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
Michael Kay
2017-04-19 10:28:16 UTC
Permalink
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
Saxonica
Post by x***@docbook-autor.de
Hi,
Post by Michael Kay
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.
declare option saxon:output "omit-all-ns-declaration=yes";
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
<ac:emoticon ac:name="warning"/>
Is there a possibility to achieve this with XQuery or Saxon?
Best regards from Germany
Michael
_______________________________________________
http://x-query.com/mailman/listinfo/talk
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk
x***@docbook-autor.de
2017-04-19 10:58:53 UTC
Permalink
Hi Michael,
Post by Michael Kay
(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
ok, first I have to check, whether Confluence is able to deal with
namespace declarations inside a wiki page anyway.

If yes anything is fine.

If not the post-processing should do it. I'm starting the transformation
with a script file so it should be easy to delete some text in the xml
output file by script too.

Fumbling around with standard sources is never a good idea (or at least
should be the very last choice IMHO).

Thanks for your quick help!

Best regards from Germany
Michael
_______________________________________________
***@x-query.com
http://x-query.com/mailman/listinfo/talk

Loading...