Getting the Node given an ITextRegion [message #214071] |
Tue, 20 May 2008 14:30  |
Eclipse User |
|
|
|
Originally posted by: dcarver.starstandard.org
Is there a way to get the DOM node of a StructuredDocument, given a
ITextRegion.
I've tried the following, but I'm not getting the Attribute Node or the
DOM node I would expect:
public static IDOMNode getNode(IStructuredDocumentRegion
documentRegion, ITextRegion textRegion) {
IStructuredModel sModel =
StructuredModelManager.getModelManager().getExistingModelFor Read(documentRegion.getParentDocument());
IDOMDocument documentNode = ((IDOMModel) sModel).getDocument();
return
(IDOMNode)documentNode.getModel().getIndexedRegion(documentR egion.getStartOffset(textRegion));
}
In particular, if I'm in an Attribute Value region, I would like to
return the DOM Node for the attribute, or at least get the TextNode for
the attribute. However, the last is something that I don't think is
implemented right in the WTP DOM implementation, as attributes aren't
returning nodes even though the DOM Level 1 spec says they can have Text
Nodes or Entity Nodes. If it returned the value as a TextNode, then it
would be a matter of just getting the parent Node.
Anyways, what is the correct way to get the information I'm looking for?
|
|
|
|
Re: Getting the Node given an ITextRegion [message #214204 is a reply to message #214153] |
Thu, 22 May 2008 08:37  |
Eclipse User |
|
|
|
Originally posted by: dcarver.starstandard.org
Nitin Dahyabhai wrote:
> Not a simple way, no. The IndexedRegion is a generic interface for
> mapping objects to document offsets, not specific to any language that's
> implemented, and for the XML DOM it's done with child nodes of the
> document, not with their attribute nodes. Once you have the main node,
> however, getting its attributes and using the offset information through
> the IDOMAttr interface should get you where you want to go. Directly
> comparing the name and value text regions of an Attr node against those
> returned through the IDOMNode interface may also work.
Thanks Nitin. I managed to get the IDOMAttr after getting the node by
first checking to make the sure the node was in the namespace I expected
and then getting the attribute by name, and comparing it's IDOMAttr
ValueRegion ITextArea#getStart to the ITextArea#getStart I had. So
basically, I now I have a convoluted way of getting a node based on the
ITextRegion.
Thanks for the tip.
|
|
|
Powered by
FUDForum. Page generated in 0.02527 seconds