Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » DOM object
DOM object [message #713910] Tue, 09 August 2011 11:15 Go to next message
Mathew Missing name is currently offline Mathew Missing nameFriend
Messages: 6
Registered: August 2011
Junior Member
I'm fighting with this all the morning and can't see any entry point.
In my plugin I'm extending XMLMultiPageEditorPart and providing some visual preview to them. I would like also to show this xml document in another view (from another point of view also). These two "items" (editor and view) should work on the same model (I assume it would be IDOMModel/IDOMDocument). But...

How to get DOM model from mentioned editor? I've got access to StructuredTextEditor, but can't see how to get to xml tree.

Greetings
Mathew
Re: DOM object [message #714343 is a reply to message #713910] Wed, 10 August 2011 11:29 Go to previous messageGo to next message
Mathew Missing name is currently offline Mathew Missing nameFriend
Messages: 6
Registered: August 2011
Junior Member
to anyone interested:
	private IDocument getXmlDocument() {
		StructuredTextEditor textEditor = (StructuredTextEditor) getAdapter(StructuredTextEditor.class);
		IDocumentProvider provider = textEditor.getDocumentProvider();
		IDocument document = provider.getDocument(textEditor.getEditorInput());
		return document;
	}

	private IDOMModel getXmlModel() {
		IDocument document = getXmlDocument();
		IStructuredModel model = null;
		model = StructuredModelManager.getModelManager()
				.getExistingModelForEdit(document);
		IDOMModel dom = (IDOMModel) model;
		return dom;
	}
Re: DOM object [message #714587 is a reply to message #714343] Thu, 11 August 2011 00:25 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 2341
Registered: July 2009
Senior Member
On 8/10/2011 7:29 AM, Mathew wrote:
> to anyone interested:
> private IDocument getXmlDocument() {
> StructuredTextEditor textEditor = (StructuredTextEditor)
> getAdapter(StructuredTextEditor.class);
> IDocumentProvider provider = textEditor.getDocumentProvider();
> IDocument document = provider.getDocument(textEditor.getEditorInput());
> return document;
> }
>
> private IDOMModel getXmlModel() {
> IDocument document = getXmlDocument();
> IStructuredModel model = null;
> model = StructuredModelManager.getModelManager()
> .getExistingModelForEdit(document);
> IDOMModel dom = (IDOMModel) model;
> return dom;
> }

Don't forget to call #releaseFromEdit() on the model when you're done.

You might also consider decoupling the view from the editor--the
selection sent across the workbench's selection service should contain
DOM Nodes, from which you can access the DOM Document and model if needed.

http://www.eclipse.org/articles/Article-WorkbenchSelections/article.html
http://wiki.eclipse.org/New_Help_for_Old_Friends_IV#Selection_in_the_XML.2FHTML.2FJSP_Editors

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


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: DOM object [message #1457647 is a reply to message #714587] Fri, 31 October 2014 14:59 Go to previous message
Swapna Mising name is currently offline Swapna Mising nameFriend
Messages: 1
Registered: July 2009
Junior Member
Hi,

I am getting null values if i use xpath to get nodes using the IDoMDocument, but the same Xpath works if we use the traditional way to DocumentBuilder .

Does the xpath construction differ for IDOMDocument ?

My xml files looks like this,
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<widget xmlns="<some link>" id="foo123.id" version="1.0.0">
<name>foo123</name>
<description>
Hello World sample application that responds to the deviceready event.
</description>
</widget>

my xpath is like this

(Element)xpath.evaluate("/widget/name", document.getDocumentElement(), XPathConstants.NODE);

Regards,
Swapna
Previous Topic:Some tags and properties are marked 'unknown' and 'undefined'
Next Topic:The WTP 3.6.1 map file
Goto Forum:
  


Current Time: Fri Dec 19 00:46:49 GMT 2014

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

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