AnsweredAssumed Answered

Validate xml against xsd

Question asked by saket.saraf on Jun 2, 2013

I am using below code to validate the xml against xsd. It works perfect however I want to pick my xsd schema file from alfresco repository. Currently I am injecting xsdPath in context file and xsd is placed in my code.

      InputStream inputStream = contentService.getReader(
               fileInfo.getNodeRef(), ContentModel.PROP_CONTENT)

         SchemaFactory factory = SchemaFactory
         String filePath = new ClassPathResource(xsdPath).getFile()
         Schema schema = factory.newSchema(new StreamSource(new File(
         Validator validator = schema.newValidator();
         validator.validate(new StreamSource(inputStream));
         return true;

Is there any way to read the xsd file from repository and pass that file to ClassPathResource? So my code will work with that modification. Or anyone have the code which will validate the xml from xsd which placed somewhere in repository.

Any quick solution or advise would be helpful.