Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » XML parseing in WST
XML parseing in WST [message #194543] Sat, 16 June 2007 15:27 Go to next message
Eclipse UserFriend
Originally posted by: nightantom.gmail.com

Hi,I have a problem with XML parsing and modeling in WST.
I learned that XML parsing in WST is slightly different from what
is done in DOM, because WST can associate the initial location information
in source file with the parsed node in XML tree.
So my question is: how could I create an XML tree of the same
kind like that by myself with the API provided by WST?
I guess that the code may be similar to the following:

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
DocumentBuilder dombuilder = factory.newDocumentBuilder();
InputStream is = new FileInputStream(new File(XMLfileName));
Document doc = dombuilder.parse(is);
Node element = doc.getDocumentElement();

Thank you very much!
Re: XML parseing in WST [message #194653 is a reply to message #194543] Mon, 18 June 2007 15:50 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 2335
Registered: July 2009
Senior Member
Nighantom wrote:
> Hi,I have a problem with XML parsing and modeling in WST.
> I learned that XML parsing in WST is slightly different from
> what is done in DOM, because WST can associate the initial location
> information in source file with the parsed node in XML tree.
> So my question is: how could I create an XML tree of the same
> kind like that by myself with the API provided by WST?
> I guess that the code may be similar to the following:
>
> DocumentBuilderFactory factory =
> DocumentBuilderFactory.newInstance();
> DocumentBuilder dombuilder = factory.newDocumentBuilder();
> InputStream is = new FileInputStream(new File(XMLfileName));
> Document doc = dombuilder.parse(is);
> Node element = doc.getDocumentElement();

It's a good guess, but not really. Creating our models has always
used the same methods regardless of whether it's an XML model, a CSS
model, or another supported content type.


org.eclipse.wst.sse.core.internal.provisional.IModelManager manager =
org.eclipse.wst.sse.core.StructuredModelManager.getModelMana ger();
org.eclipse.wst.sse.core.internal.provisional.IStructuredMod el model =

org.eclipse.wst.sse.core.internal.provisional.IModelManager. getModelForRead(IFile);
org.eclipse.wst.xml.core.internal.provisional.document.IDOMM odel
domModel =

(org.eclipse.wst.xml.core.internal.provisional.document.IDOM Model)
model;
Document doc = domModel.getDocument();


Everything inside of that document should then implement
org.eclipse.wst.xml.core.internal.provisional.document.IDOMN ode, a
superset of the W3C Node interface.

Every call to IModelManager.getModelForRead() should be paired with
a IStructuredModel.releaseFromRead(), using a try{}..finally{}
construct if possible. Models should be treated as if they were
system resources, and should always be cleanly released. If you
want to save changes you make to the model, use getModelForEdit()
and releaseFromEdit() instead.

--
Nitin Dahyabhai
Structured Source Editor


---
Nitin Dahyabhai
Eclipse WTP, IBM
Re: XML parseing in WST [message #194675 is a reply to message #194653] Tue, 19 June 2007 13:40 Go to previous message
Eclipse UserFriend
Originally posted by: nightantom.gmail.com

Thank you very much, Mr. Dahyabhai!
It's really a great help for me!
Previous Topic:WTP 2.0 RC3 - Bad link in downloads page
Next Topic:Eclipse 3.3 Junit test runner restarts server always.
Goto Forum:
  


Current Time: Wed Nov 26 17:38:13 GMT 2014

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

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