Skip to main content



      Home
Home » Language IDEs » ServerTools (WTP) » DOM object
DOM object [message #713910] Tue, 09 August 2011 07:15 Go to next message
Eclipse UserFriend
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 07:29 Go to previous messageGo to next message
Eclipse UserFriend
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] Wed, 10 August 2011 20:25 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: DOM object [message #1457647 is a reply to message #714587] Fri, 31 October 2014 10:59 Go to previous message
Eclipse UserFriend
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:JavaScript files with UTF-8 encoding
Next Topic:The WTP 3.6.1 map file
Goto Forum:
  


Current Time: Wed Jul 23 21:13:00 EDT 2025

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

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

Back to the top