Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Question about structured models and validation
Question about structured models and validation [message #66039] Wed, 19 January 2005 07:09 Go to next message
Geoff Longman is currently offline Geoff LongmanFriend
Messages: 49
Registered: July 2009
Member
Hi,

Have a question about XMLModels and validating programatically. In short
I'm adapting a project builder that parses a pile of XML files and (if
they are well formed and valid) traverses the DOM tree building some
objects.

(I'm trying to avoid a long story here so bear with me...I'm learning by
trying things out)

Currently (preWTP) I'm parsing the files to DOM myself and catching
parse and validation errors.

I'd like to use the XMLModels provided by WTP instead as I can ask for a
DOM rep by calling getDocument().

ie. by doing stuff like this:

Document doc = null;
IModelManager mm = StructuredModelManager.getInstance()
.getModelManager();
IStructuredModel model = null;
try {
model = mm.getExistingModelForRead((IFile) myFile);
if (model == null || !(model instanceof XMLModel))
return;

doc = ((XMLModel) model).getDocument();
} finally {
if (model != null)
model.releaseFromRead();
}

and I get a w3c Document object regardless of the fact that a file may
not be well formed or valid.

Question is: How does one use WTP to check if the file is well formed
and valid before (or after) getting the XMLModel and obtaining a w3c
Document?

thx,

Geoff
Re: Question about structured models and validation [message #66083 is a reply to message #66039] Wed, 19 January 2005 08:14 Go to previous messageGo to next message
Lawrence Mandel is currently offline Lawrence MandelFriend
Messages: 486
Registered: July 2009
Senior Member
Hi Geoff,

You can programmatically call XML validation using the XML validator
located in org.eclipse.wst.xml.validation as follows.

XMLValidator validator = new XMLValidator();
// You may want to set a URI resolver for custom resource resolution. In
Eclipse the validator is configured to use the
org.eclipse.common.uri.resolver
XMLValidationReport report = validator.validate(filename);

The validation report will tell you if the file is valid and will provide
error and warning messages if it isn't.

Please note that the API for the XML validator (and most of the WTP
project) is not final yet and may change.


Lawrence
Re: Question about structured models and validation [message #66338 is a reply to message #66083] Wed, 19 January 2005 16:37 Go to previous message
Geoff Longman is currently offline Geoff LongmanFriend
Messages: 49
Registered: July 2009
Member
lmandel@ca.ibm.com wrote:
> Hi Geoff,
>
> You can programmatically call XML validation using the XML validator
> located in org.eclipse.wst.xml.validation as follows.
>
> XMLValidator validator = new XMLValidator();
> // You may want to set a URI resolver for custom resource resolution. In
> Eclipse the validator is configured to use the
> org.eclipse.common.uri.resolver
> XMLValidationReport report = validator.validate(filename);
>
> The validation report will tell you if the file is valid and will provide
> error and warning messages if it isn't.

Perfect! Thanks very much!

>
> Please note that the API for the XML validator (and most of the WTP
> project) is not final yet and may change.
>

Noted.

Cheers,

Geoff

>
> Lawrence
Previous Topic:wtp cvs (today) db server bug
Next Topic:Obtaining an (unmanaged?) XMLModel for a IStorage (JarEntryFile)
Goto Forum:
  


Current Time: Fri Jan 03 07:37:26 GMT 2025

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

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

Back to the top