How can I write an XML string in Stax without duplicating namespaces

37 views
Skip to first unread message

David Thielen

unread,
Jun 10, 2018, 4:41:03 PM6/10/18
to Woodstox User Mailing List
Part way through creating an XML file with Stax I have some XML in the form of a String. I write this to the Stax output.

It all works great except namespaces used in the passed in XML, that are defined in the root element, are duplicated again in the inner nodes. 

I know this is legal, but it's cluttered. Is there any way to avoid this?


thanks - dave

Tatu Saloranta

unread,
Jun 12, 2018, 12:56:32 AM6/12/18
to David Thielen, Woodstox User Mailing List
If there is already an existing valid binding (*) for Namespace URI, that should be used. So Woodstox should already handle this, if (and only if) generator has "namespace repairing"
mode enabled. If behavior differs, filing a bug report would make sense.

-+ Tatu +-

(*) attributes can not use default namespace binding, for example; but this example used explicit prefixes not default namespace

 

David Thielen

unread,
Jun 12, 2018, 7:22:34 AM6/12/18
to Tatu Saloranta, Woodstox User Mailing List

Hi;

 

The namespace repair option seems to screw up the use of default namespaces which we have also. Is there way to get this where some attributes can use the default namespace?

 

We are writing DOCX files and so we need to use the namespaces of the XML files in the DOCX file.

--
You received this message because you are subscribed to the Google Groups "Woodstox User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to woodstox-use...@googlegroups.com.
To post to this group, send email to woodst...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/woodstox-user/CAGrxA26aGiieo9bauMicyA95eGHsGNqjn13tedXuqd%2B%2Bp-5RbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Tatu Saloranta

unread,
Jun 12, 2018, 10:33:17 AM6/12/18
to David Thielen, Woodstox User Mailing List
On Tue, Jun 12, 2018 at 4:22 AM, David Thielen <da...@windward.net> wrote:

Hi;

 

The namespace repair option seems to screw up the use of default namespaces which we have also. Is there way to get this where some attributes can use the default namespace?


Attributes never use the default namespace; this is XML limitation by specification, not Woodstox limitation.
Non-prefixed attributes always belong to "empty" namespace, regardless of binding of the default namespace.
That is, their namespace URI is "". Default namespace binding only applies to elements.
 

We are writing DOCX files and so we need to use the namespaces of the XML files in the DOCX file.


I am not sure what you mean by this.

-+ Tatu +-
 

 

 

From: woodst...@googlegroups.com [mailto:woodstox-user@googlegroups.com] On Behalf Of Tatu Saloranta
Sent: Monday, June 11, 2018 10:57 PM
To: David Thielen <da...@windward.net>
Cc: Woodstox User Mailing List <woodstox-user@googlegroups.com>
Subject: Re: How can I write an XML string in Stax without duplicating namespaces

 

On Sun, Jun 10, 2018 at 1:41 PM, David Thielen <da...@windward.net> wrote:

Part way through creating an XML file with Stax I have some XML in the form of a String. I write this to the Stax output.

 

It all works great except namespaces used in the passed in XML, that are defined in the root element, are duplicated again in the inner nodes. 

 

I know this is legal, but it's cluttered. Is there any way to avoid this?

 

 

If there is already an existing valid binding (*) for Namespace URI, that should be used. So Woodstox should already handle this, if (and only if) generator has "namespace repairing"

mode enabled. If behavior differs, filing a bug report would make sense.

 

-+ Tatu +-

 

(*) attributes can not use default namespace binding, for example; but this example used explicit prefixes not default namespace

 

 

--

You received this message because you are subscribed to the Google Groups "Woodstox User Mailing List" group.

To unsubscribe from this group and stop receiving emails from it, send an email to woodstox-user+unsubscribe@googlegroups.com.


To post to this group, send email to woodst...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages