Home » Language IDEs » ServerTools (WTP) » Get Attribute, Tag and Parent name
Get Attribute, Tag and Parent name [message #677037] |
Tue, 07 June 2011 07:32  |
Eclipse User |
|
|
|
Hi all,
I am trying to get a kind of content assist for XML attributes.
At the moment I am working with the class org.eclipse.wst.xml.ui.internal.XMLTemplateCompletionProcessor.java
Is has a method addAttributeValueProposals. This method is called, of course, when content assist is invoked inside double quotes for attribute values.
The list of attribute values, in my case, is inside an external XML file.
For example:
<employee department=""
If the content assist is invoked, a list of possible department should be displayed inside the box.
If the question start to write something inside double quotes I can get what he writes using ContentAssistRequest.getMatchString; but what if the content assist is invoked without typing anything?
Here come the questions:
1) How do I get the name of the attribute? I also need the name of the tag which attribute belongs to and the name of the parent tag.
2) Then, with these data, I can build an XPath expression to query the external XML file (no problem here).
When I get my data back...how do I put them inside the content assist block?
Thanks a lot
Marco
EDIT: probably the names of the attribute and parent can be get using method always inside ContentAssistRequest, probably...
[Updated on: Tue, 07 June 2011 08:00] by Moderator
|
|
|
Re: Get Attribute, Tag and Parent name [message #677224 is a reply to message #677037] |
Tue, 07 June 2011 16:57   |
Eclipse User |
|
|
|
On 6/7/2011 7:32 AM, MarcoGT wrote:
> Hi all,
>
> I am trying to get a kind of content assist for XML attributes.
> At the moment I am working with the class
> org.eclipse.wst.xml.ui.internal.XMLTemplateCompletionProcessor.java
I hope you mean
org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor.
> Is has a method addAttributeValueProposals. This method is called, of
> course, when content assist is invoked inside double quotes for
> attribute values.
>
> The list of attribute values, in my case, is inside an external XML file.
>
> For example:
>
> <employee department=""
>
> If the content assist is invoked, a list of possible department should
> be displayed inside the box.
>
> If the question start to write something inside double quotes I can get
> what he writes using ContentAssistRequest.getMatchString; but what if
> the content assist is invoked without typing anything?
The match string will be empty.
> Here come the questions:
>
> 1) How do I get the name of the attribute? I also need the name of the
> tag which attribute belongs to and the name of the parent tag.
In
org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor#addAttributeValueProposals(ContentAssistRequest)
you'll see it walk backwords through the list of text regions in the tag
to find the attribute's name. The ContentAssistRequest contains the DOM
Node you're working on as well as its parent Node.
>
> Then, with these data, I can build an XPath expression to query the
> external XML file (no problem here).
>
> When I get my data back...how do I put them inside the content assist
> block?
You'll add the proposal using
ContentAssistRequest.addProposal(ICompletionProposal).
--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational
|
|
|
Re: Get Attribute, Tag and Parent name [message #677303 is a reply to message #677224] |
Wed, 08 June 2011 02:08   |
Eclipse User |
|
|
|
Nitin Dahyabhai wrote on Tue, 07 June 2011 16:57On 6/7/2011 7:32 AM,
I hope you mean
org.eclipse.wst.xml.ui.internal.contentassist.XMLContentAssistProcessor.
I saw that this class in no longer used (it is deprecated) and it suggests to use XMLStructuredContentAssistProcessor
The called method when invoking content assist on an attribute values is XMLTemplatesCompletionProposaleComputer.addAttributeValueProposals, not that one in XMLContentAssistProcessor that, as said, is deprecated.
I mean, when calling the Content Assistant the called method is XMLTemplatesCompletionProposaleComputer.addAttributeValueProposals (I tried to put breakpoints and System.out.print and this is the method that is invoked)
See also here: http://wiki.eclipse.org/New_Help_for_Old_Friends_V#Content_Assist (in the "Deprecated" section).
The new class is XMLStructuredContentAssistProcessor but it is very different from XMLContentAssistProcessor, for example there is not method addAttributeValueProposals. The same is for the super classes.
AbstractContentAssistProcessor, which is extended by XMLContentAssistProcessor is deprecated and it is suggested to use StructuredContentAssistProcessor.
So, which method get the attribute name, tag and parent tag name?
The method you told me (org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor#addAttributeValueProposals(ContentAssistRequest) ) is inside a deprecated class.
Quote:
The match string will be empty.
Ok, but of course I can make as well an XPath query to my external XML file using the attribute name, tag name a parent tag name, right?
Quote:
In
org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor#addAttributeValueProposals(ContentAssistRequest)
you'll see it walk backwords through the list of text regions in the tag
to find the attribute's name. The ContentAssistRequest contains the DOM
Node you're working on as well as its parent Node.
As before, this class is deprecated too, the "new" one is "StructuredContentAssistProcessor"
Quote:
You'll add the proposal using
ContentAssistRequest.addProposal(ICompletionProposal).
If I do:
List proposals = new ArrayList();
proposals.add(xpr.read(MY_XPATH_EXPRESSION, XPathConstants.STRING));
ICompletionProposal result = (ICompletionProposal) proposals;
contentAssistRequest.addProposal(result);
I get a cast error at the third line.
One more thing: if I call the content assist inside "attribute value position", is also possible to get the list of all the attributes inside that element, if any, with their values?
Thanks
Marco
[Updated on: Wed, 08 June 2011 09:00] by Moderator
|
|
| | | | | | | |
Re: Get Attribute, Tag and Parent name [message #686162 is a reply to message #684714] |
Mon, 20 June 2011 11:23  |
Eclipse User |
|
|
|
On 6/16/2011 1:14 AM, MarcoGT wrote:
> No, I will not submit it.
>
> So, do I have to sign it?
That's a detail of deployment that I'm not an expert on, apart from
having seen my own updated plug-ins be ignored when a previous signed
version was installed.
--
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational
|
|
|
Goto Forum:
Current Time: Wed Jul 23 03:34:29 EDT 2025
Powered by FUDForum. Page generated in 0.29313 seconds
|