Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > [XML] XSD Schema Validation

Reply
Thread Tools

[XML] XSD Schema Validation

 
 
oziris
Guest
Posts: n/a
 
      09-28-2005
Hi,

Is there a way to validate a XSD schema?
I perform a validation of a XML file according to this schema with

<code>
SchemaFactory schemaFactory =
SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schemaXSD = schemaFactory.newSchema(fichierXSD);
Validator validateur = schemaXSD.newValidator();
validateur.validate(fichierXML);
</code>

but I would like as well to perform a validation of *the schema*.

Thanks.

-o--

 
Reply With Quote
 
 
 
 
Timbo
Guest
Posts: n/a
 
      09-28-2005
oziris wrote:
> Hi,
>
> Is there a way to validate a XSD schema?
> I perform a validation of a XML file according to this schema with
>
> <code>
> SchemaFactory schemaFactory =
> SchemaFactory.newInstance(
> XMLConstants.W3C_XML_SCHEMA_NS_URI);
> Schema schemaXSD = schemaFactory.newSchema(fichierXSD);
> Validator validateur = schemaXSD.newValidator();
> validateur.validate(fichierXML);
> </code>
>
> but I would like as well to perform a validation of *the schema*.
>

But against what are you validating it? The XML file is being
validated with respect to the format specified in the schema. I
think the best you could do with regards to the XSD schema is a
syntax check, and a few other checks the jaxb gives you, such as
no duplicate names etc. Anything other validation would need to be
by hand.
 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      09-28-2005
So you want a schema for a schema? You can just treat the schema as an
XML file and validate it as normal. If you are looking to make sure
it's a valid schema file there are standard xsd's and dtd's out there
that will validate schemas.

If that's not what you are looking to do, I guess you'll have to
elaborate on your question.

Thanks,

~Chris

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-28-2005


oziris wrote:


> Is there a way to validate a XSD schema?
> I perform a validation of a XML file according to this schema with
>
> <code>
> SchemaFactory schemaFactory =
> SchemaFactory.newInstance(
> XMLConstants.W3C_XML_SCHEMA_NS_URI);
> Schema schemaXSD = schemaFactory.newSchema(fichierXSD);


I think that call compiles and validates the schema, you need to set up
an error handler to be informed about any errors during compilation and
validation of the schema e.g. do
schemaFactory.setErrorHandler(yourErrorHandler);
before you call newSchema. The error handler needs to implement
org.xml.sax.ErrorHandler.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
oziris
Guest
Posts: n/a
 
      09-28-2005
Hi Chris,

Thanks for your reply.
Where could I get such standard xsd's ? I'm a little bit lost

-o--

 
Reply With Quote
 
oziris
Guest
Posts: n/a
 
      09-28-2005
Hi Martin,

I thought a SAXParseException was thrown even if no ErrorHandler were
defined.
That is not the case in my app.

-o--

 
Reply With Quote
 
oziris
Guest
Posts: n/a
 
      09-28-2005
Hi Timbo,

It's what I thought at first but I read begins of pseudo-solution. I
find a kind of confirmation that it's possible or not.

-o--

 
Reply With Quote
 
oziris
Guest
Posts: n/a
 
      09-28-2005
Please read "I look for" instead of "I find". Sorry for my poor english


-o--

 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      09-28-2005
http://www.w3.org/2001/XMLSchema.xsd is the reference schema for the
schema language.

Beware it's big, and you really don't want to validate your schema
everytime you need to validate an XML file. But when you are authoring
your schema, it's useful, especially when you don't have a schema
authoring tool

~Chris

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-28-2005


oziris wrote:


> I thought a SAXParseException was thrown even if no ErrorHandler were
> defined.


I have just tried it here to set up a simple Error handler which reports
any errors/warnings to System.out and then I have tried it with a schema
that intentionally contains some errors (e.g. typos like minOcurs for
the minOccurs attribute) and those errors are reported to the error
handlers as follows:

Recoverable parse error: org.xml.sax.SAXParseException:
s4s-att-not-allowed: Attribute 'minOcurs' cannot appear in element
'element'.

where the error handler is set as follows:

schemaFactory.setErrorHandler(new ErrorHandler () {
public void error (SAXParseException parseException) {
System.out.println("Recoverable parse error: " + parseException);
}
public void fatalError (SAXParseException parseException) {
System.out.println("Fatal parse error: " + parseException);
}
public void warning (SAXParseException parseException) {
System.out.println("parse warning: " + parseException);
}
});

So that way you get any errors reported during compilation and
validation of the schema.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation with XSD using XML::LibXML::Schema, and XML::Validator::Schema huntingseasonson@gmail.com Perl Misc 5 11-29-2006 12:37 PM
Validation of XSD (XML Schema) against XSD Rushi XML 1 12-09-2005 08:12 AM
XML schema - Make xsd include another xsd stiank81 XML 4 06-26-2005 05:11 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
XML validation with schema xsd in JAVA Mavrick Java 1 09-09-2004 12:22 PM



Advertisments