Home Forums General XMetaL Discussion What is selected Reply To: What is selected

Derek Read

Reply to: What is selected

A few guesses based on what you have asked…

Selection.ContainerNode will give you the current node. At that point you can walk the DOM tree to find out the nodes within that node. This can be done various ways (and will need to be depending on what information you need). There is an example in the Programmers Guide called “Node example: A simple tree-walker” that might help, and you will also want to read the section called “Overview of the DOM interfaces”.

There is also the API called getNodesByXPath() that you might use to obtain a list of child elements within the current context.

It is also possible to use the Selection or Range APIs such as GotoNext(), MoveToElement(), MoveUp/Down/Left/Right(), SelectBeforeContainer(), etc, to do similar (but not really) operations as can be done using DOM calls. In some cases these can be easier to work with than the DOM and in some cases the DOM is more powerful. They are different however, with Selection and Range being tied more closely to what a user can select. The DOM is more abstract and for some people more difficult to get your head around.

If you need to know what 'type' of element the user is in you can use InContextOfType().

You might also wish to have a look at the journalist.mcr file which is part of the Journalist demo. It contains a lot of sample code, some of which you might be able to reuse.