Hi,
Take a look at this blog entry
http://blog.parthenoncomputing.com/xerces/archives/2005/04/can_i_validate.html
Cheers,
Gareth
Gregor wrote:
Hello,
I am trying to validate Schema files using Xerces.
The problem is, that I only got one XML Schema file e.g. attA001.xsd (some will now, this is the W3Cs Schema-test-collection http://www.w3.org/2001/05/xmlschema-test-collection.html) and want to tell whether it is a valid XML Schema according to XML Schema recommendation or an invalid one.
I tried the following approaches:
1.) Download the Schema-for-Schemas from the W3Cs Website ("http://www.w3.org/2001/XMLSchema.xsd") and validating attA001.xsd against this file as if attA001.xsd was an instance (which technically in my understanding it is) of XMLSchema.xsd (Please see code snippet below) (Before doing that I validated the XMLSchema.xsd against its own internal dtd which worked just fine)
2.) Validate an empty file specifing attA001.xsd as Schema file for it (hope it would appart from empty file err also point to errors in the schema (..schema-full-checking", true); but it did not.
I ran out of ideas at some point yesterday night.
I am very thankfull for any suggestions.
Kind Regards,
Gregor
1.) Code Snippet This is the setup: (try/catch omitted for legibility)
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setFeature("http://xml.org/sax/features/namespaces", true); reader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
reader.setFeature("http://xml.org/sax/features/validation", true);
reader.setFeature("http://apache.org/xml/features/validation/schema", true);
reader.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
true); Validator handler=new Validator(); reader.setErrorHandler(handler);
parser.setProperty
("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource",
"C:/test/XMLSchema.xsd");
parser.parse(SchemaUri, handler);
//SchemaUri = "C:/test/attA001.xsd"
This is the errorMsg:
s4s-elt-invalid-content.1: The content of '#AnonType_documentation' is invalid. Element 'attribute' is invalid, misplaced, or occurs too often.
Line Number:1277
I can not find the specified element and I get the same error for many xsds I am trying to validate (even the ones supposed to be valid according to W3Cs XML Schema test collection)
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Gareth Reakes, Managing Director Parthenon Computing +44-1865-811184 http://blog.parthenoncomputing.com/xerces
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]