Page 1 of 1

Inserting XML fragment adds xmlns="" attribute

Posted: Wed Jun 24, 2009 5:53 pm
by sijomon
Hi (me again),

I am developing a framework operation. The operation is responsible for surrounding a piece of text selected in the author window with some XML retrieved from a web app. The XML coming back from the webapp looks like this:

<legis-cite title="Directive 80/68 on the Protection of Groundwater Against Pollution" type="eudirective" year="1979" div-num="art1" div-seq="001" div-depth="1" lcr:id="111428075">
<ancestor-part div-num="root" div-seq="001" div-depth="0" lcr:id="294967762"></ancestor-part>
</legis-cite>

When I add it to the document using:

authorAccess.surroundInFragment(citation, offset, end);

the XML that gets inserted looks like this:

<legis-cite title="Directive 80/68 on the Protection of Groundwater Against Pollution" type="eudirective" year="1979" div-num="art1" div-seq="001" div-depth="1" lcr:id="111428075" xmlns="">
<ancestor-part div-num="root" div-seq="001" div-depth="0" lcr:id="294967762"></ancestor-part>
</legis-cite>

NOTE the additional 'xmlns=""' attribute in the top level legis-cite element.

Has anyone any ideas why this attribute is being added and what I can do to prevent it? Please bear in mind I'm a Java nerd not an XML nerd ;)

Many thanks,

Simon.

Re: Inserting XML fragment adds xmlns="" attribute

Posted: Thu Jun 25, 2009 8:24 am
by Radu
Hello Simon,

When we made the author extensions we made the decision that XML fragments inserted with the specific insert actions needed to have the namespace fully specified on them.

So if your main XML file looks like:

Code: Select all


<root xmlns="http://rootns.com">
........................
</root>
and you want to add an XML fragment in the same namespace the fragment will have to be:

Code: Select all


<fragXML xmlns="http://rootns.com">
...........
</fragXML>
When the fragment will get inserted, the extra namespace declaration will get deleted.
If your fragment does not explicitly specify the namespace, it will be considered in no-namespace and the additional xmlns="" attribute will be added to it to enforce that.

In your particualar case, the XML fragment you are trying to insert should be something like:

<legis-cite xmlns="http://the/namespace/of/the/main/xml.file"
.................
</legis-cite>

Regards,
Radu

Re: Inserting XML fragment adds xmlns="" attribute

Posted: Thu Jun 25, 2009 10:59 am
by sijomon
Thanks for the response.

Is there a way to programtically dertrmine the default namespace of the currently active document from an Opertaion class? I can't seem to find it on the AuthorAccess object, am I just missing it?

Simon.

Re: Inserting XML fragment adds xmlns="" attribute

Posted: Thu Jun 25, 2009 11:17 am
by Radu
Hi Simon,

The code should be something like:

Code: Select all


    AuthorNode contextNode = authAccess.getDocumentController().getNodeAtOffset(insertOffset);
if(contextNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
String ns = ((AuthorElement)contextNode).getNamespace();
}
Regards,
Radu

Re: Inserting XML fragment adds xmlns="" attribute

Posted: Thu Jun 25, 2009 11:32 am
by sijomon
Yes that works perfectly.

many thanks.

Simon.