From: Stefan B. <bo...@ap...> - 2009-05-13 04:07:00
|
Hi, Both current XMLUnit implementations support Validation of XML pieces against XML Schema defitions or DTDs - in the .NET case this only works if the instance document contains a Schema or DTD reference and the reference can be resolved AFAICS. The Java version has two different validator classes, one based on the "old" validation model where the document is validated as a side effect of parsing (similar to the way .NET works) and a different one using javax.xml.validation - which doesn't do DTDs but in theory supports RelaxNG and other schema languages. All three of them return booleans to indicate whether an instance is valid, the .NET code and the old Java validator provide a single string message for the validation error(s) - the new Java validator provides a list of exceptions. The "new" Java validator can validate schema defitions in addition to schema instances. I like this even if I don't know how to implement it for .NET or for DTDs in Java, yet. The .NET and old Java code use a model of "one validator per instance document", the new Java code uses one instance per schema definition. All in all I tend to prefer the "new" Java API as a model for how XMLUnit2 should do validation, but I'd rather use a ValidationError class than a SAXParserException as a holder for the validation errors. So a first sketch - leaving out things like resolvers for now - could look like (no public/private qualifiers on attributes, just think .NET properties or Java getters/setters): class ValidationError { readonly int line; // with a negative constant for UNKNOWN readonly int column; // ditto readonly String message; } .NET knows warnings in addition to errors, I'm not sure how we should handle them. class ValidationResult { readonly bool valid; readonly Iterable/IEnumerable<ValidationError> errors; } class Validator { String schemaURI; // should that be an URI instead? probably wouldn't // work for DTDs then Source[] schemaSources; ValidationResult validateSchema(); ValidationResult validateInstance(Source); } Since the Java code will be prettier if it uses different implementations for DTDs and W3C Schema I suggest to add a factory method class Validator { static Validator forLanguage(String); } using the strings defined in javax.xml.XmlConstants for DTD and W3C schema. We may also add a static isLanguageSupported method so people can probe for e.g. RelaxNG support. .NET would define a string for XDR and support DTD, W3C schema and XDR, Java would support DTD (by parsing) and anything SchemaFactory supports. Am I on track here? Stefan |