Custom plugin: adding attributes in the specified order
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 176
- Joined: Wed Apr 29, 2009 4:55 pm
Custom plugin: adding attributes in the specified order
Dear All,
in my custom plugin action, I am trying to set several attributes, but all of them are sorted alphabetically in the result XML code. Is there any way to keep the insertion order?
For example, if my 'ulink' element has 'url' attribute and additional 'type' attribute is added, it is placed before the 'url', not after it.
I am adding attributes using this command:
Thanks, Jan
in my custom plugin action, I am trying to set several attributes, but all of them are sorted alphabetically in the result XML code. Is there any way to keep the insertion order?
For example, if my 'ulink' element has 'url' attribute and additional 'type' attribute is added, it is placed before the 'url', not after it.
I am adding attributes using this command:
Code: Select all
authorAccess.getDocumentController().setAttribute("type", new AttrValue("variable"), uLinkNode);
-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Custom plugin: adding attributes in the specified order
Hi Jan,
The attributes order is not relevant for the semantic meaning of the XML document.
From what I think the Author mode should kind of preserve by default the order in which the attributes were added.
Is it possible that in the Preferences->"Editor / Format / XML" page you have checked the "Sort attributes" checkbox?
Regards,
Radu
The attributes order is not relevant for the semantic meaning of the XML document.
From what I think the Author mode should kind of preserve by default the order in which the attributes were added.
Is it possible that in the Preferences->"Editor / Format / XML" page you have checked the "Sort attributes" checkbox?
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 176
- Joined: Wed Apr 29, 2009 4:55 pm
Re: Custom plugin: adding attributes in the specified order
That 'Sort attributes' option is disabled. I agree the order is just a cosmetic issue. My action is a kind of shortcut to common manual action. Such side-effect breaks the consistency 

-
- Posts: 9434
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Custom plugin: adding attributes in the specified order
Hi,
So I made this operation to experiment a bit:
I invoked it on an element in the Author mode and the XML in the Text editing mode looks like this:
So the order in which you add the attributes is obeyed at serialization.
Regards,
Radu
So I made this operation to experiment a bit:
Code: Select all
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws AuthorOperationException {
try {
AuthorElement elem = (AuthorElement) authorAccess.getDocumentController().getNodeAtOffset(authorAccess.getEditorAccess().getCaretOffset());
authorAccess.getDocumentController().setAttribute("zz", new AttrValue("val1"), elem);
authorAccess.getDocumentController().setAttribute("yy", new AttrValue("val2"), elem);
authorAccess.getDocumentController().setAttribute("aa", new AttrValue("val3"), elem);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
Code: Select all
<body zz="val1" yy="val2" aa="val3"/>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 176
- Joined: Wed Apr 29, 2009 4:55 pm
Re: Custom plugin: adding attributes in the specified order
You are correct! During my experiments, I haven't switched to Text mode and now I can see it is correct there all the time.
I've finally found a dedicated option for this behavior: Preferences...|Editor|Edit Modes|Author: Sort attributes alphabetically for "Full Tags with Attributes" which is my default mode. When unchecked, I have the correct order also in Author mode.
Thanks a lot!
I've finally found a dedicated option for this behavior: Preferences...|Editor|Edit Modes|Author: Sort attributes alphabetically for "Full Tags with Attributes" which is my default mode. When unchecked, I have the correct order also in Author mode.
Thanks a lot!
Return to “SDK-API, Frameworks - Document Types”
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