hi
I've tried this code to validate XML using xsd file:
Code:
public static void validate(String xmlFilePath, URL schemaFileUrl)
{
try
{
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);// stop standard validation to allow
// custom schema
factory.setNamespaceAware(true);
SchemaFactory schemaFactory = SchemaFactory
.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
factory.setSchema(schemaFactory.newSchema(schemaFileUrl));
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
// Register the error handler
reader.setErrorHandler(new JS_ValidationError());
// Parse the file as the first argument on the command-line
reader.parse(xmlFilePath);
}
catch (SAXException e)
{
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
} catch (IOException e)
{
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
} catch (ParserConfigurationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I have called this method ,but it issues this error :"unknown protocol" followed by windows partition name, in the debug I found that the value of the url is "
file://
(windows-partiton-char)/rest of path" !!!
this should work but it doesn't!!
so how can I fix this problem?
thanks