Page 1 of 1

Remove Namespace from selected node

Posted: Fri Nov 21, 2014 11:38 am
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

Re: Remove Namespace from selected node

Posted: Fri Nov 21, 2014 12:27 pm
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

Re: Remove Namespace from selected node

Posted: Fri Nov 21, 2014 1:00 pm
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

Re: Remove Namespace from selected node

Posted: Fri Nov 21, 2014 1:24 pm
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

Re: Remove Namespace from selected node

Posted: Fri Nov 21, 2014 4:01 pm
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

Re: Remove Namespace from selected node

Posted: Mon Nov 24, 2014 1:07 pm
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

Re: Remove Namespace from selected node

Posted: Tue May 19, 2015 11:02 am
by Radu
Hi,

The initial described behavior should be fixed in Oxygen 17.0.

Regards,
Radu