List of attributes for a node

Post here questions and problems related to editing and publishing DITA content.
maxim.kovalev
Posts: 35
Joined: Fri Nov 11, 2011 10:34 am

List of attributes for a node

Post by maxim.kovalev »

How can I get a list of attributes for a node?
I found this way. Get a node on the spot where the cursor is positioned. The following is a AuthorNode AuthorElement. And call the AuthorElement.getAttributeAtIndex(i);
However, this method returns only attributes that are installed. And how can you get a complete list of attributes that are possible for this node (as in panel attributes).
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: List of attributes for a node

Post by mihaela »

Hi Maxim,

To find all the possible attributes for a node you have to get the WhatAttributesCanGoHereContext from the document schema manager and then ask the schema manager what attributes are available in this context.
The following code sample list the names of all attributes available for the element at caret position:

Code: Select all


  int caretOffset = authorAcess.getEditorAccess().getCaretOffset();

AuthorDocumentController controller = authorAcess.getDocumentController();
// Get the node at caret position
AuthorNode node = controller.getNodeAtOffset(caretOffset);

if (node instanceof AuthorElement) {
AuthorSchemaManager authorSchemaManager = controller.getAuthorSchemaManager();
// From schema manager get the current context
WhatAttributesCanGoHereContext context = authorSchemaManager.createWhatAttributesCanGoHereContext((AuthorElement) node);
// Find the list of all possible attributes for the current context
List<CIAttribute> possibleAttrs = authorSchemaManager.whatAttributesCanGoHere(context);
if (possibleAttrs != null) {
for (CIAttribute ciAttribute : possibleAttrs) {
System.out.println("Attr: " + ciAttribute.getName());
}
}
}
Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
maxim.kovalev
Posts: 35
Joined: Fri Nov 11, 2011 10:34 am

Re: List of attributes for a node

Post by maxim.kovalev »

mihaela wrote:Hi Maxim,

To find all the possible attributes for a node you have to get the WhatAttributesCanGoHereContext from the document schema manager and then ask the schema manager what attributes are available in this context.
The following code sample list the names of all attributes available for the element at caret position:

Code: Select all


  int caretOffset = authorAcess.getEditorAccess().getCaretOffset();

AuthorDocumentController controller = authorAcess.getDocumentController();
// Get the node at caret position
AuthorNode node = controller.getNodeAtOffset(caretOffset);

if (node instanceof AuthorElement) {
AuthorSchemaManager authorSchemaManager = controller.getAuthorSchemaManager();
// From schema manager get the current context
WhatAttributesCanGoHereContext context = authorSchemaManager.createWhatAttributesCanGoHereContext((AuthorElement) node);
// Find the list of all possible attributes for the current context
List<CIAttribute> possibleAttrs = authorSchemaManager.whatAttributesCanGoHere(context);
if (possibleAttrs != null) {
for (CIAttribute ciAttribute : possibleAttrs) {
System.out.println("Attr: " + ciAttribute.getName());
}
}
}
Regards,
Mihaela
Cool, thanks
Post Reply