Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Getting DOM from StructuredTextEditor
Getting DOM from StructuredTextEditor [message #213305] Tue, 06 May 2008 13:32 Go to next message
Philippe Sabourin is currently offline Philippe SabourinFriend
Messages: 28
Registered: July 2009
Junior Member
Is there an easy way to get a org.w3c.dom document out of a
StructuredTextEditor using eclipse's built in xml classes. The selection
providers do use some XML/Dom organization, but what if I want to get the
whole document as an DOM object? I was using dom4j and just getting the
content of the editor as a string and parsing it, but it seems dumb to use
that and have to go back and forth from dom4j to w3c.dom stuff, while
eclipse already does some XML interaction. Any solution for this?

Thanks,
Philippe
Re: Getting DOM from StructuredTextEditor [message #213381 is a reply to message #213305] Wed, 07 May 2008 04:03 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Philippe Sabourin wrote:
> Is there an easy way to get a org.w3c.dom document out of a
> StructuredTextEditor using eclipse's built in xml classes. The selection
> providers do use some XML/Dom organization, but what if I want to get
> the whole document as an DOM object? I was using dom4j and just getting
> the content of the editor as a string and parsing it, but it seems dumb
> to use that and have to go back and forth from dom4j to w3c.dom stuff,
> while eclipse already does some XML interaction. Any solution for this?

Any DOM Node can give you its owner document using
Node.getOwnerDocument(), but you can also ask the editor for its
org.eclipse.wst.sse.ui.internal.provisional.extensions.ISour ceEditingTextTools
adapter and cast the result to
org.eclipse.wst.xml.ui.internal.provisional.IDOMSourceEditin gTextTools.
That interface provides a method to obtain the DOM Document.

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


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Getting DOM from StructuredTextEditor [message #213709 is a reply to message #213381] Tue, 13 May 2008 18:31 Go to previous messageGo to next message
Philippe Sabourin is currently offline Philippe SabourinFriend
Messages: 28
Registered: July 2009
Junior Member
Will changes to this document automatically be reflected in the Structured
editor, or do I still need to write it to that editor.
Re: Getting DOM from StructuredTextEditor [message #213716 is a reply to message #213381] Tue, 13 May 2008 18:43 Go to previous messageGo to next message
Philippe Sabourin is currently offline Philippe SabourinFriend
Messages: 28
Registered: July 2009
Junior Member
Also, this method only gives you a shell of the XML, with many of the
commands missing (such as getTextContent()). Is there a way to get the
full XML?
Re: Getting DOM from StructuredTextEditor [message #213731 is a reply to message #213716] Tue, 13 May 2008 20:51 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Philippe Sabourin wrote:
> Also, this method only gives you a shell of the XML, with many of the
> commands missing (such as getTextContent()). Is there a way to get the
> full XML?
>

The current model is on DOM Level 1 API compliant, it doesn't implement
all of DOM Level 2 and none of DOM Level 3. DOM Level 3 implements the
getTextContent(). You can use getNodeValue() or another DOM Level 1
api to get the information.

If you need DOM Level 2 and Level 3 support, I would suggest opening a
bug report to ask for it.

In the meantime, you can make an equivalant function by following the
example at the end of this article:

http://www.cafeconleche.org/books/xmljava/chapters/ch12.html
Re: Getting DOM from StructuredTextEditor [message #213739 is a reply to message #213731] Tue, 13 May 2008 21:04 Go to previous messageGo to next message
Philippe Sabourin is currently offline Philippe SabourinFriend
Messages: 28
Registered: July 2009
Junior Member
David Carver wrote:

> Philippe Sabourin wrote:
>> Also, this method only gives you a shell of the XML, with many of the
>> commands missing (such as getTextContent()). Is there a way to get the
>> full XML?
>>

> The current model is on DOM Level 1 API compliant, it doesn't implement
> all of DOM Level 2 and none of DOM Level 3. DOM Level 3 implements the
> getTextContent(). You can use getNodeValue() or another DOM Level 1
> api to get the information.

> If you need DOM Level 2 and Level 3 support, I would suggest opening a
> bug report to ask for it.

> In the meantime, you can make an equivalant function by following the
> example at the end of this article:

> http://www.cafeconleche.org/books/xmljava/chapters/ch12.html

/**
* getNodeValue method
*
* @return java.lang.String
*/
public String getNodeValue() throws DOMException {
return null;
}

getNodeValue doesnt seem to be implemented either, unless it's in some
subclass of NodeImpl.java.

Philippe
Re: Getting DOM from StructuredTextEditor [message #213747 is a reply to message #213739] Tue, 13 May 2008 21:26 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Philippe Sabourin wrote:

> getNodeValue doesnt seem to be implemented either, unless it's in some
> subclass of NodeImpl.java.

That's how it should be. The documentation for getNodeValue()
specifies a null result for certain Node types.

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


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Getting DOM from StructuredTextEditor [message #213763 is a reply to message #213747] Wed, 14 May 2008 02:26 Go to previous message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

Nitin Dahyabhai wrote:
> Philippe Sabourin wrote:
>
>> getNodeValue doesnt seem to be implemented either, unless it's in some
>> subclass of NodeImpl.java.
>
> That's how it should be. The documentation for getNodeValue() specifies
> a null result for certain Node types.
>

Correct. The following link gives a list of when something can return a
non-null value getNodeValue();

http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#ID- 1950641247

If it's an element node, you are working with, then you must check to
see if there are descendants, the textual value if there is any will be
available in the returned Text node.

For the most part the way the DOM is implemented in WTP, is valid and
correct. However, out of 500 unit tests, there are about 150 of them
that the current DOM Level 1 doesn't pass.

See bug 214439 (http://bugs.eclipse.org/214439) for more information.
Most of these are probably edge cases, and in one particular case a
wrong assumption on whether Attributes can contain nodes. They can
according the spec, and the nodes are Text or entity nodes.

dave
Previous Topic:developing RIA with eclipse
Next Topic:Add Cluster member using WTP
Goto Forum:
  


Current Time: Thu Apr 25 06:02:40 GMT 2024

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

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

Back to the top