Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Getting the Node given an ITextRegion
Getting the Node given an ITextRegion [message #214071] Tue, 20 May 2008 18:30 Go to next message
Eclipse UserFriend
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 #214153 is a reply to message #214071] Wed, 21 May 2008 22:15 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

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.

--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Getting the Node given an ITextRegion [message #214204 is a reply to message #214153] Thu, 22 May 2008 12:37 Go to previous message
Eclipse UserFriend
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.
Previous Topic:Using a JavaScript library in an existing project
Next Topic:"Classpath entry ... will not be exported or published" warnings
Goto Forum:
  


Current Time: Fri Apr 19 10:57:40 GMT 2024

Powered by FUDForum. Page generated in 0.02558 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top