Remove Namespace from selected node

Post here questions and problems related to editing and publishing DITA content.
Denis
Posts: 47
Joined: Thu Jun 19, 2014 3:55 pm

Remove Namespace from selected node

Post by Denis »

Hi,

we are using the Eclipse Oxygen Author in Version 15.2.

My use case is to copy the content from a selected node and save it.

I get the node, which content will be copied from this method:

Code: Select all

authorEditorPageBase.getFullySelectedNode()

Then I create AuthorDocumentFragment with this method:

Code: Select all

documentController.createDocumentFragment(authorNode, copyContent);
documentController.serializeFragmentToXML(fragment);
When I serialize the fragment there is an class attribute with the namespace from DITA on the node.

The problem is that the dtd do not allow this attribute on this node.
Is it possible to filter this attribute, before serializing it?

Best regards
Denis
Denis Zygann
KGU Consulting GmbH
http://www.kgu-consulting.com
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: Remove Namespace from selected node

Post by Dan »

Hello Denis,

There is no API to filter out the namespaces from the node or fragment.
I sugest you post-process the serialized output (fiter it using SAX for instance).

Best regards,
Dan
Denis
Posts: 47
Joined: Thu Jun 19, 2014 3:55 pm

Re: Remove Namespace from selected node

Post by Denis »

Hi Dan

Is there another way to copy the content from a node and its childs without to generating the namespace?

From my point of view its seems to be an bug, because I only want to copy the content and the namespace will be set on your side silently.

Best regards,
Denis
Denis Zygann
KGU Consulting GmbH
http://www.kgu-consulting.com
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Re: Remove Namespace from selected node

Post by Dan »

For the moment there is no way to do that.

I understand your use case. For instance, when serializing a 'p' element you get something like:

Code: Select all


<p xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" xmlns=""> some text </p>
For sure you do not need the 'ditaarch' namespace declaration, as it not used at all.
The xmlns="" is also redundant, having it or not on a root element without prefix does not make any difference.

Just a note: When inserting such a fragment with redundant namespaces into another DITA document, the namespaces are automatically cleared, so you won't have a problem. For instance copying the above 'p' element from a Docbook document and pasting into a DITA topic will clear its declarations, because they are already defined by the root of the topic (default attibute values).

I will record an issue about filtering the namespace declarations that are not necessary or redundant.
We will notify you when this will be ready. Until then, please post-process the serialized result.

Thank you,
Dan
Denis
Posts: 47
Joined: Thu Jun 19, 2014 3:55 pm

Re: Remove Namespace from selected node

Post by Denis »

Hi

In our case the user can also open the copied content. So if he does so, the root element is this one with the namespace declaration in it. So the opened document is not valid and he has to remove it. This is quite annoying for a user.

Best regards
Denis
Denis Zygann
KGU Consulting GmbH
http://www.kgu-consulting.com
alex_jitianu
Posts: 1016
Joined: Wed Nov 16, 2005 11:11 am

Re: Remove Namespace from selected node

Post by alex_jitianu »

Hi Denis,

Like my colleague Dan said, right now you have to post process the fragment. What I wanted to add is that you could just execute a replace on the existing string. Something like this:

Code: Select all


AuthorDocumentFragment fragment = documentController.createDocumentFragment(authorNode, copyContent);
String serialized = documentController.serializeFragmentToXML(fragment);
serialized = serialized.replace("xmlns:ditaarch=\"http://dita.oasis-open.org/architecture/2005/\" xmlns=\"\"", "");
Best regards,
Alex
Radu
Posts: 9424
Joined: Fri Jul 09, 2004 5:18 pm

Re: Remove Namespace from selected node

Post by Radu »

Hi,

The initial described behavior should be fixed in Oxygen 17.0.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply