XML parseing in WST [message #194543] |
Sat, 16 June 2007 15:27  |
Eclipse User |
|
|
|
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   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04598 seconds