Inserting XML fragment adds xmlns="" attribute
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 83
- Joined: Wed May 20, 2009 1:18 pm
Inserting XML fragment adds xmlns="" attribute
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.
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.
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Inserting XML fragment adds xmlns="" attribute
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:
and you want to add an XML fragment in the same namespace the fragment will have to be:
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
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>
Code: Select all
<fragXML xmlns="http://rootns.com">
...........
</fragXML>
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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 83
- Joined: Wed May 20, 2009 1:18 pm
Re: Inserting XML fragment adds xmlns="" attribute
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.
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.
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Inserting XML fragment adds xmlns="" attribute
Hi Simon,
The code should be something like:
Regards,
Radu
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();
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service