Thanks for the replies.. Its really helpful in the sense I have started with something now.
However I am still in problems
I have written the following sample xsd.
<xs:schema id="NewDataSet" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns="">
<xs:element name="input_parameters">
<xs:complexType>
<xs:sequence>
<xs:element name="type" type="xs:string" minOccurs="1" />
<xs:element name="param1" type="xs:string"
minOccurs="1" />
<xs:element name="param2" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
with the sampleInput.xml as
<?xml version="1.0" encoding="UTF-8"?>
<input_parameters>
</input_parameters>
The
java code is to do the validation is using SAX
public static void validateSchema(
String schemaURL, String xmlURL){
SAXParser parser = new SAXParser();
XMLValidationErrorHanlder errorHandler = new XMLValidationErrorHanlder();
parser.setErrorHandler(errorHandler);
try {
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemaURL);
parser.parse(xmlURL);
} catch (SAXNotRecognizedException e) {
e.printStackTrace();
} catch (SAXNotSupportedException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
My question is, the xsd says for some elements the minOccur is 1. I haven't put any data in the xml. Still the parser is successful without giving any error. Is there any way I can findout if any required field is missing. or may be there is an extra field in the XML then that should also be detected.