akhter.saeed
Lurker
try {
DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setNamespaceAware(true);
DocumentBuilder parser = parserFactory.newDocumentBuilder();
Document document = parser.parse(new File(SDCardManager.getSDCardManagerInstance().getBaseDir() + "/"
+ xmlName));
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(new File(SDCardManager.getSDCardManagerInstance().getBaseDir()
+ "/file.xsd"));
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(document));
return true;
} catch (Exception e) {
Log.e("XML Exception", e.getMessage());
return false;
}
i am trying this code to validate the XML using XSD schema but i am facing an illegalArgumentException on
(SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)).Kindly help me out that how to resolve it....
DocumentBuilderFactory parserFactory = DocumentBuilderFactory.newInstance();
parserFactory.setNamespaceAware(true);
DocumentBuilder parser = parserFactory.newDocumentBuilder();
Document document = parser.parse(new File(SDCardManager.getSDCardManagerInstance().getBaseDir() + "/"
+ xmlName));
// create a SchemaFactory capable of understanding WXS schemas
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
// load a WXS schema, represented by a Schema instance
Source schemaFile = new StreamSource(new File(SDCardManager.getSDCardManagerInstance().getBaseDir()
+ "/file.xsd"));
Schema schema = factory.newSchema(schemaFile);
// create a Validator instance, which can be used to validate an instance document
Validator validator = schema.newValidator();
// validate the DOM tree
validator.validate(new DOMSource(document));
return true;
} catch (Exception e) {
Log.e("XML Exception", e.getMessage());
return false;
}
i am trying this code to validate the XML using XSD schema but i am facing an illegalArgumentException on
(SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)).Kindly help me out that how to resolve it....