Skip to main content



      Home
Home » Language IDEs » ServerTools (WTP) » Question about structured models and validation
Question about structured models and validation [message #66039] Wed, 19 January 2005 02:09 Go to next message
Eclipse UserFriend
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 03:14 Go to previous messageGo to next message
Eclipse UserFriend
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 11:37 Go to previous message
Eclipse UserFriend
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: Mon Apr 28 02:37:31 EDT 2025

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

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

Back to the top