How to get value from xml element
Answered
How to get a value from XmlFile, in FindUsagesProvider#canFindUsagesFor I receive XmlFile element I don't understand how can I get a value that user pressed.
`<CUSTOMER NAME="somename"/>`
If I pressed NAME I receive how can I retrieve "somename", unfortunately after some researches, I can't still figure it out even after reading https://plugins.jetbrains.com/docs/intellij/xml-dom-api.html
Please sign in to leave a comment.
Did you try my suggestion given here? https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010542660-How-to-register-findusagesprovider?page=1#community_comment_360002941439
Building the functionality using XML DOM API will not require to implement FindUsagesProvider.
Not yet sorry, I want to try with another way
<dom.fileMetaData implementation="com..." rootTagName="sometag"/>
I implemented as well <codeInsight.lineMarkerProvider language="XML" implementationClass="com...."/>
And I need to implement RelatedItemLineMarkerProvider that has a method collectNavigationMarkers(element PsiElement)
Essentially it is the same element that I receive in findUsagesProvieder, to make the question clearer I mentioned FindUsagesProvieder
And about your answer, I didn't try yet because I found the solution with fileMetadata and will try this if I'm not successfull
Thanks for the answer, I definitely will try your solution even I'm successful with the current solution, I just have barely enough time to devote to plugin development.
Using extension point <dom.fileMetadata> _is_ actually DOM API.
Regarding providing resolving/navigation, please see also "Resolving" section in DOM docs https://plugins.jetbrains.com/docs/intellij/xml-dom-api.html#resolving
RelatedItemLineMarker should receive all XmlElements in this file, then you can use code like:
if (element instanceof XmlTag)
DomElement domElement= com.intellij.util.xml.DomManager#getDomElement(com.intellij.psi.xml.XmlTag)
to test/get data from DOM model, use com.intellij.codeInsight.navigation.NavigationGutterIconBuilder to assist building.
Thanks, your suggestion with XmlTag helped to properly define the target, but when I press CTRL + B on an attribute it doesn't lead me to line appropriate line, all I see is a glutter, and if I press the glutter it leads me to the correct place.
How can I not show any icon but when press CTRL + B it would lead me to the correct place?
dom.fileMetadata as far as I understand is the description of XML but in my case, the description is not static it is dynamic and changed.
I don't get the link about XmlDom API Resolving can help me with that?
1) CTRL-B shortcut is bound to "Goto Declaration" action and not related to gutter navigation in any way
2) you can define DOM scheme in dynamic way by using com.intellij.util.xml.reflect.DomExtender extension point
3) not sure what your question is, please have a look in IJ Community sources to see real world usages of how com.intellij.util.xml.ResolvingConverter is used in DOM scenarios
I started implementing using PsiReferenceProvider, it works only if there is a declaration is in place navigation doesn't work, though MyPsiReferenceProvider is triggered when I open the XML file even when I press CTRL + B it triggers
MyXmlReference extends PsiReferenceBase<PsiElement> implements PsiPolyVariantReference
all his methods multiResolve and resolve
if XML looks like this
the implementation of PsiReferenceProvider works properly, how to make it works properly without touching the XML declaration?