How to access selected DOM node in plugin?

  • Hi,

    Still another question!

    My XML files contains project tags, which I can select from the DOM tree or the Jaxe window.

    When I have select one I want to run a plugin related to the contents of only this particular project.

    How can I refer to the currently selected project within a plugin?


  • - JaxeDocument.elementA(pos) returns the Jaxe element at the position in the JTextPane
    - JaxeDocument.elementsDans(dpos, fpos) returns the list of Jaxe elements between the 2 positions
    - JaxeElement.noeud is the DOM node for the Jaxe element
    - JaxeDocument.textPane is the JaxeTextPane for the document
    - JaxeTextPane inherits from JTextPane, so you can use JTextPane methods such as getSelectionStart to find the cursor position and selection

    you should be able to find the selected project(s) with these methods

  • Hi,

    Thanks for your response!

    Okay, experimented a bit, but how can I distinguish between a <project> and </project> tag? Probably a very basic issue!


  • I'm not sure what you mean. Tags are just one of many ways to display an element. Also, you can't select invalid markup, so you can't select the start tag without the end tag and vice versa.
    If you want to know more precisely where a Jaxe element is, you can use JaxeElement's debut (start) and fin (end) attributes: they are the positions of the first and last characters in the document within the Jaxe element.

  • Hi,

    I try to understand the start and end of each JaxeElement and did some debugging.

    I started with an XML file containing tree project-tags within the root tag called projects:


    Next I selected the last project and below present part of my debugging info from my plugin (I only printed the NONE JETexte elements!):

    JaxeElement (0): Element: jaxe.elements.JEString  noeud: projects  debut: 0  fin: 2005
    JaxeElement (11): Element: jaxe.elements.JEString  noeud: project  debut: 11  fin: 647

    which looks okay to me, although I don't understand the projects element, because I didn't select that one!

    And what about the end part:

    JaxeElement (647): Element: jaxe.elements.JEString  noeud: project  debut: 11  fin: 647
    JaxeElement (650): Element: jaxe.elements.JEString  noeud: project  debut: 650  fin: 1310
    JaxeElement (665): Element: jaxe.elements.JEString  noeud: header  debut: 665  fin: 877

    I'd expect only one closing project tag, but no 2 project tags, and certainly not a header tag at the end. Within the project tag there is a header-tag, but not outside it! Isn't that strange? I also don't see a closing projects tag. This leaves me confused! Probably I don't understand a basic concept here!