Page 1 of 1

Accessing DOM Model

Posted: Tue Oct 23, 2018 2:04 am
by jlpoole
In JavaScript, I want to be able to get a handle on the root node, i.e. a DOM Level 1 Core node in a document tree, of a document for a given window being edited in Oxygen Author. I prefer being able to work in JavaScript and am used to facilitating work in a JavaScript environment using Java when necessary to implement a class.

I'm coming from Arbortext Editor where I have developed code using the Arbortext Command Language, aka "ACL", Java, and JavaScript. I have been reviewing the javadoc at https://www.oxygenxml.com/InstData/Editor/SDK/javadoc/ and I have reviewed all the topics in the SKD-API Forum that hint of being able to instantiate a DOM object and then walk through the nodes. Unfortunately, I do not seem to have come across examples I was hoping for.

For example, if I have an XML document opened in Editor named abc.xml in window1 and another efg.xml opened in window2, where can I determine what open windows there are in the Author editing session and then access the documents therein?

Once I have a document handle, I'd have a recursive function that would visit each and every node where I can then perform some checks. A real-life example would be to walk a document's nodes and populate a subset of elements with attributes, e.g. "PID", which is populated from an array I obtain from a database. I have the database connection worked out, it's the walk-through of an instantiated DOM that I am having trouble finding.

Could someone provide an example of querying what window is opened in a session, and then after selecting a window, e.g. the one holding abc.xml, getting a handle on the root node of the DOM therein? I'm assuming that once I have the handle on the root node, then the W3C DOM methods and properties are available to walk through and manipulate the model.

Thank you.

Re: Accessing DOM Model

Posted: Tue Oct 23, 2018 8:20 am
by Radu
Dear John,

Oxygen has Java-based API to add a listener which listens for edited file selection events and using this API you can gain access to the DOM-like model in the Author visual editing mode and edit it.
This Java-based API can be used either from a Java-based plugin:

https://www.oxygenxml.com/doc/versions/ ... lugin.html

and there is a sample plugin here:

https://github.com/oxygenxml/sample-plu ... ace-access

or the same Java-based API can be used from a Javascript-based plugin:

https://www.oxygenxml.com/doc/versions/ ... in-js.html

and we have some sample Javascript-based plugins here:

https://github.com/oxygenxml/wsaccess-j ... le-plugins

I just created a specific Javascript-based plugin which adds a popup menu action in the Author visual editing mode, action which wraps the current selection in an XML element:

https://github.com/oxygenxml/wsaccess-j ... AuthorPage

The sample plugin above also contains various API references.

Please see some specific answers below:
Could someone provide an example of querying what window is opened in a session,


In our API we have a "WSEditor" object corresponding to each opened XML document, so this would be the equivalent of your "window" term.

https://www.oxygenxml.com/InstData/Edit ... ditor.html

Once your plugin's "applicationStarted" callback is received, you can use the received "StandalonePluginWorkspace" to add a listener which will be notified when a WSEditor is opened, selected or closed:

https://www.oxygenxml.com/InstData/Edit ... space.html

Each opened "WSEditor" has inside it three editor modes (or pages), the Text editing mode, the Grid editing mode and the Author editing mode. For each of these editing modes you have API to manipulate their internal XML content.
The API to manipulate the Author editing mode is: https://www.oxygenxml.com/InstData/Edit ... rPage.html
and then after selecting a window, e.g. the one holding abc.xml, getting a handle on the root node of the DOM therein?
Using the "WSAuthorEditorPage" API you can gain access to the "AuthorDocumentController":

https://www.oxygenxml.com/InstData/Edit ... ntroller--

The controller gives you access to the root "AuthorDocument" node, gives you methods to find nodes using XPath expressions and to make changes to the nodes. All changes MUST be made through the controller API.
I'm assuming that once I have the handle on the root node, then the W3C DOM methods and properties are available to walk through and manipulate the model.
The structure of "AuthorNode" nodes is similar to the DOM method but it needs to be changed using the controller:

https://www.oxygenxml.com/InstData/Edit ... rNode.html

Also (and the screenshot in the link above shows it more clearly) the text content is not preserved in nodes, it's preserved as a single contiguous segment of text in which each AuthorNode has two sentinels, two special characters marking the start and end of each AuthorNode.

Regards,
Radu

Re: Accessing DOM Model

Posted: Tue Oct 23, 2018 7:58 pm
by jlpoole
Hi Radu,

This is great. Thank you, having the details you have included is very helpful. The approach of capturing handles on events to instantiate objects rather than having just an object tree that is accessible any time is something I found difficult to digest. Now that you have provided an example, it becomes much more clearer.

Again, thank you.

John